【问题标题】:Django templates: tags in tagsDjango 模板:标签中的标签
【发布时间】:2016-01-20 04:30:58
【问题描述】:

在 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/">

【问题讨论】:

    标签: django templates tags


    【解决方案1】:

    我认为这会起作用

    base.html

    <form method="POST" action="{% block url %}{% endblock %}">
     ...
    </form>
    

    home.html

    {% block url %} {% url 'lists:newList' %} {% endblock %}
    

    【讨论】:

    • 像魅力一样工作!谢谢。
    猜你喜欢
    • 2014-07-25
    • 2014-03-20
    • 2011-02-09
    • 2014-04-03
    • 2021-02-18
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 2010-12-19
    相关资源
    最近更新 更多