Forums

How to add line numbers into the text area which is created by using Django forms ?

Hi,

This question is related to Python Django.

I am creating a website similar to Ideone.com I want my text area to display line numbers as I increase the lines of code writing into it.

Following is the code for my form:-

from django import forms

class DevelopmentForm(forms.Form):
    App_Name = forms.CharField(max_length=100)
    Python_Code = forms.CharField(widget=forms.Textarea)

    def clean_Python_Code(self):
        message = self.cleaned_data['Python_Code']
        file_object = open("/home/ulmastersproject/Remote_Software_Development/App/Code.py", "wb+")
        file_object.write(message)
        file_object.close()

        num_words = len(message.split())
        if num_words < 4:
            raise forms.ValidationError("Not enough code!")
        return message

Appreciate your help / suggestions

Thanks, San

To do that, you'd probably have to write your own editing control in in Javascript in the browser or use an existing one. There are quite a large number of different ones and a bit of googling will throw up a large number that you can choose from based on your needs.

Thanks Glen