Answer the question
In order to leave comments, you need to log in
Wrap code in Django tag?
Hello!
I am developing my blog on Django, the following difficulty arose:
I insert code fragments into the blog, how can I wrap this code in a code, pre tag for a beautiful display?
I read about displaying code in HTML, how to do it manually, but on my site the article is displayed like this: {{ blog_post.article_text|linebreaksbr|urlize }}
As you can see from my example, I used template tags - linesbreaksbr, urlize.
Is there a similar solution for processing program code?
I think the essence of the issue is clear, if the processing method is not a template tag, then please just point me in the right direction, I want to figure it out myself.
Answer the question
In order to leave comments, you need to log in
Make your own filter, wrap the data in a css class
. For example, bootstrap has code
A in the project:
# -*- coding: utf-8 -*-
from django import template
register = template.Library()
@register.filter(name="get_code")
def get_code(value):
return '<code>%s</code>' % value
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question