Generic detail view UserProfileDetailView must be called with either an object pk or a slug in the URLconf

前端 未结 3 1420
长发绾君心
长发绾君心 2021-01-22 16:37

Well I am facing error and it\'s now its been two days to this question and still stuck on this mistake, anybody can help and able to fix this. I am new in Django and need help.

3条回答
  •  灰色年华
    2021-01-22 17:11

    Set slug_url_kwarg--(Django Doc) and slug_field--(Django Doc) attributes on your view class

    
    class UserProfileDetailView(DetailView):
        slug_url_kwarg = "username" # this the `argument` in the URL conf
        slug_field = "your_model_field" # this is the model field name.
    
        # Rest of your code

提交回复
热议问题