I want to apply a syntax highlighter to a django TextField but unable to do so. Please suggest.

I have tried using AceWidget to textfield but it end up with below error: TypeError: __init__() got an unexpected keyword argument 'widget'

class CodeHiglighter(models.Model)
    name = models.CharField(max_length=50)
    h_code = models.TextField(widget=AceWidget)

I need to apply python syntax highlighter to TextField

2 Answers

Jibin Mathews On

You need to use widget on your form not on model

class CodeHiglighter(forms.Form)
    name = forms.CharField(max_length=50)
    h_code = forms.TextField(widget=AceWidget)

Community On

I don't know about AceWidget, but some tutorials I've been following use the pygments library which may help you. There's a django example here.

Pygments homepage example.