django use Pk field in a url

前端 未结 1 1002
谎友^
谎友^ 2020-12-22 09:57

I have created a pk field(not automatically created by the model). when I want to use this pk name(in my case school_id) I got this error:

Generic detail vie         


        
相关标签:
1条回答
  • 2020-12-22 10:22

    Add pk_url_kwarg = 'school_pk' to view SchoolDetailView. By default it is set to pk.

    class SchoolDetailView(DetailView):
        context_object_name = 'school'
        model = models.School
        template_name = 'basic_app/school_detail.html'
        pk_url_kwarg = 'school_pk'
    
    0 讨论(0)
提交回复
热议问题