django酥脆形式与jinja2 [英] django crispy forms with jinja2
本文介绍了django酥脆形式与jinja2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
遇到未知标签crispy。 Jinja正在寻找以下标签:'endblock'。需要关闭的最内部的块是'block'。
我的模板代码:
{%extends'base.html'%}
{%load crispy_forms_tags%}
{%block content%}
< div class =panel-heading >< H3>注册及LT; / H3>< / DIV>
{%crispy form%}
{%endblock%}
我一起使用这个应用程序?
解决方案
更好的解决方案:
templatetags .py
从crispy_forms.utils导入render_crispy_form
from django_jinja import library
from jinja2 import contextfunction
@contextfunction
@ library.global_function
def crispy(context,form):
return render_crispy_form(form,context = context)
在模板中:
{{crispy(form)}}
I want to use Jinja2 and Django crispy forms together, but when I load crispy_forms_tags in my template and trying to render form with this template tag, I get an error:
Encountered unknown tag 'crispy'. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'.
My template code:
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block content %}
<div class="panel-heading"><h3>Registration</h3></div>
{% crispy form %}
{% endblock %}
How can I use this apps together?
解决方案
Better solution:
templatetags.py
from crispy_forms.utils import render_crispy_form
from django_jinja import library
from jinja2 import contextfunction
@contextfunction
@library.global_function
def crispy(context, form):
return render_crispy_form(form, context=context)
In template:
{{ crispy(form) }}
这篇关于django酥脆形式与jinja2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文