Django reverse url with parameters to a class based view

前端 未结 1 2041
情歌与酒
情歌与酒 2021-01-17 22:24

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.

thes

1条回答
  •  独厮守ぢ
    2021-01-17 23:01

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

    0 讨论(0)
提交回复
热议问题