Django Url, Slug for Detail Page

后端 未结 2 825
故里飘歌
故里飘歌 2020-12-14 11:08

I\'m having trouble configuring my url to display a detail view. Clicking on this link: {{ blog.name }}

2条回答
  •  轮回少年
    2020-12-14 11:26

    Rudolf absolutely right

    The /$ stopped blog from catching all the subpages which called by slug so if you have subpages you need to add /$ to folder level as follow:

    re_path('brands/$', AllBrands.as_view(), name="brands"),
    re_path(r'^brands/(?P[\w-]+)/$', BrandDetail.as_view(), name = 'brandetail'),
    

    This is django 2.2

    Without /$ after brands, the slug page was showing the brands listing page.

提交回复
热议问题