Django Class Based Views, get_absolute_url not working

后端 未结 5 1371
闹比i
闹比i 2021-02-10 17:57

I bought and am Reading the Book Two Scoops of Django:Best Practices for Django 1.5 and in it has a example of Class based views. After this implementation I get the error afte

5条回答
  •  孤街浪徒
    2021-02-10 18:19

    When you use reverse, use the name of the url pattern you wish to reverse.

    You wish to redirect to this url:

    url(
        regex=r'^NonProfit/(?P[-\w\d]+)/',
        view=NonProfitDetailView.as_view(),
        name='NonProfit'
        )
    

    Therefore your get_absolute_url method should be:

    def get_absolute_url(self):
        return reverse("NonProfit", kwargs={"slug": self.slug})  
    

提交回复
热议问题