Django 模板:标签中的标签
Django templates: tags in tags
在 Django 模板中,我试图在另一个标签中包含一个标签:
项目的urls.py
:
url(r'^lists/', include('lists.urls', namespace='lists')),
lists
应用的 urls.py
:
url(r'^new/$', views.newList, name='newList'),
url(r'^(?P<listID>[0-9]+)/$', views.viewList, name='viewList'),
base.html:
<form method="POST" action="{% {% block url %}{% endblock %} %}">
...
</form>
home.html:
{% block url %} url 'lists:newList' {% endblock %}
list.html:
{% block url %} url 'lists:viewList' {{list.id}} {% endblock %}
好像不行。
home.html的结果是
<form method="POST" action=" url 'lists:newList' ">
而不是我想要的:
<form method="POST" action="/lists/new/">
我认为这会奏效
base.html
<form method="POST" action="{% block url %}{% endblock %}">
...
</form>
home.html
{% block url %} {% url 'lists:newList' %} {% endblock %}
在 Django 模板中,我试图在另一个标签中包含一个标签:
项目的urls.py
:
url(r'^lists/', include('lists.urls', namespace='lists')),
lists
应用的 urls.py
:
url(r'^new/$', views.newList, name='newList'),
url(r'^(?P<listID>[0-9]+)/$', views.viewList, name='viewList'),
base.html:
<form method="POST" action="{% {% block url %}{% endblock %} %}">
...
</form>
home.html:
{% block url %} url 'lists:newList' {% endblock %}
list.html:
{% block url %} url 'lists:viewList' {{list.id}} {% endblock %}
好像不行。 home.html的结果是
<form method="POST" action=" url 'lists:newList' ">
而不是我想要的:
<form method="POST" action="/lists/new/">
我认为这会奏效
base.html
<form method="POST" action="{% block url %}{% endblock %}">
...
</form>
home.html
{% block url %} {% url 'lists:newList' %} {% endblock %}