CppLearner
CppLearner

Reputation: 17040

Show source code with synatx highlight in Django html page

I searched around and doesn't seem to have any good solutions.

The closest one: django-pygments doesn't support template context/variable passing as language option.

I want to know if anyone one know of a good solution that supports snippet type passed as template context?

Thanks.

Upvotes: 0

Views: 249

Answers (1)

Burhan Khalid
Burhan Khalid

Reputation: 174624

Template:

{% content|pygmentize:lang %}

View:

def show(request):
    ctx = dict()
    ctx['content'] = 'alert("hello");'
    ctx['lang'] = 'javascript'
    return render(request,'template.html',ctx)

Upvotes: 1

Related Questions