I just started learning python and django and I have a question. I got the assignment to turn function views into class based views. But my links wont work now.
我刚开始学习python和django,我有一个问题。我得到了将函数视图转换为基于类的视图的赋值。但我的链接现在不起作用。
these are from urls.py:
这些来自urls.py:
url(r'^$', ContactIndex.as_view()),
url(r'^add$', ContactAdd.as_view()),
url(r'^([0-9]+)/update$', ContactUpdate.as_view()),
url(r'^([0-9]+)/view$', ContactView.as_view()),
This is my link :
这是我的链接:
{% url rtr_contact.views.ContactView contact.id %}
but this doesnt work it says:
但这不起作用它说:
Caught NoReverseMatch while rendering: Reverse for 'rtr_contact.views.ContactView' with arguments '(20L,)' and keyword arguments '{}' not found.
17
To make url reversing easy, I recommend that you always name your url patterns.
为了使网址翻转变得容易,我建议您始终为网址模式命名。
url(r'^$', ContactIndex.as_view(), name="contact_index"),
url(r'^add$', ContactAdd.as_view(), name="contact_add"),
url(r'^([0-9]+)/update$', ContactUpdate.as_view(), name="contact_update"),
url(r'^([0-9]+)/view$', ContactView.as_view(), name="contact_view"),
Then in the template:
然后在模板中:
{% url contact_view contact.id %}
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2011/12/21/6954b15f84c10697e9e1b0adad41dfda.html。