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 %}

更多相关文章

  1. 从django视图中的按钮获取click事件
  2. 使用nasm和ld汇编/链接问题
  3. 解决nfs链接开发板出现:nfs:server is not responding,still tryi
  4. 我应该在哪里添加Yocto位烤任务来创建工作文件夹符号链接?
  5. Linux中动态链接库总结
  6. 删除目录软链接注意事项
  7. 求GridControl_11.1.0.1.0_Linux_x86-64_1of3 的下载链接最好是
  8. 用GCC编译链接程序--编译链接器GCC常用功能(菜鸟级)
  9. 对于Linux创建链接时终目录和文件处理的认识

随机推荐

  1. Android分析View的scrollBy()和scrollTo(
  2. Android(安卓)UI 优化 使用和 标签
  3. 【Android语音合成TTS】云知声离线TTS使
  4. Android静默安装和静默卸载
  5. Android实时抓包分析 : 善用adb调试桥
  6. Android事件分发机制详解:史上最全面、最
  7. 【android】使用android-resource-remove
  8. Android(安卓)Map Api 使用和开发(1) 添
  9. Android(安卓)OpenGLES2.0(三)——等腰直角
  10. Android应用程序窗口(Activity)的运行上下