Django反向url与参数到基于类的视图
16lz
2021-01-22
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.
1 个解决方案
#1
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 %}
更多相关文章
- 从django视图中的按钮获取click事件
- 使用nasm和ld汇编/链接问题
- 解决nfs链接开发板出现:nfs:server is not responding,still tryi
- 我应该在哪里添加Yocto位烤任务来创建工作文件夹符号链接?
- Linux中动态链接库总结
- 删除目录软链接注意事项
- 求GridControl_11.1.0.1.0_Linux_x86-64_1of3 的下载链接最好是
- 用GCC编译链接程序--编译链接器GCC常用功能(菜鸟级)
- 对于Linux创建链接时终目录和文件处理的认识