Forums

Anyone had luck adding line numbers to django textarea using codemirror?

I know it should be possible since all the editing pages on PA have it. And for my simple uses, I'd be content enough to just use full paths to the pythonanywhere served javascript/css if I could then determine the proper settings to add this option to my form's textarea served from within my django app in PA. Anyone accomplished that? I honestly don't know if PA is using pure jQuery codemirror or the djangocodemirror from 0.5.2http://pypi.python.org/pypi/djangocodemirror.

I've tried the long route myself trying to use djangocodemirror and hit a brick wall. I made a git clone and was following the directions at http://pypi.python.org/pypi/djangocodemirror . After putting a copy of everything in the static file in the clone in my static folder for my app, making a separate app folder in myproject folder with the djangocodemirror folder that held settings_local.py, forms.py, models.py & etc, and adding the app to my app list in settings.py in myproject folder (although kept giving a sever error when I followed the directions to list 'djangocodemirror' and instead listed 'myproject.djangocodemirror'), I get the error 'No module named djangocodemirror.fields' when I try to add code making such a form in my views.py file. Here is my code in views.py that seems to be causing the issue: :::python from djangocodemirror.fields import CodeMirrorWidget

class CodeMirrorSampleForm(forms.Form):
   content = forms.CharField(label="Your content", widget=CodeMirrorWidget(codemirror_only=True, codemirror_attrs={'lineNumbers':True}))

   def save(self, *args, **kwargs):
       return

We don't use CodeMirror, we use ace. It's working really well for us, maybe it's worth a look for you?

Thanks, Glenn. That was helpful. I made a stripped down version using code from a PA page with an editor. And got that basic page working within my django app. I don't have it perfectly integrated with my real app page quite yet; however, this got me way past my roadblock.

@wayne461 Congrats!!

Getting better. You definitely pointed me in the right direction.

They have nice demos over at the ace-build site! I was able to easily get the scrollable one running on a page in my django app on PA with all the src files coming from within my own static folder. (After easily cloning from github in a PA bash shell.) I think this will serve me well and will be easier to integrate into my real page.