Задать вопрос

Тел: +7 965 3737 888

441

Просмотров

0

Ответов

render_markup filter, specify the markup filter as a string

<p>Ever since django.contrib.markup appeared I've added a markup_lang field to my models where I want to support multiple input formats. This filter lets you pass the filter name as a string (from your model field, for example) and it will call the appropriate filter. I use None when the text is HTML, in which case it will return as-is.</p>
<p>Example:</p>
class Article(models.Model):
    content = models.TextField(null=False, default="")
    markup_lang = models.CharField(maxlength=20, blank=True)

a = Article(content="**Test!**", markup_lang='textile')
b = Article(content="&lt;h1&gt;Hello!&lt;/h1&gt;")

<p>And in a template:</p>
{% for article in article_list %}
    {{ article.content|render_markup:article.markup_lang }}
{% endfor %}

Вопрос полезен? Да0/Нет0
file_2651.py(446.0б)
None