Django class-based view: How do I pass additional parameters to the as_view method?

后端 未结 7 732
悲哀的现实
悲哀的现实 2020-11-28 19:00

I have a custom class-based view

# myapp/views.py
from django.views.generic import *

class MyView(DetailView):
    template_name = \'detail.html\'
    model         


        
相关标签:
7条回答
  • 2020-11-28 19:59

    If your urlconf looks something like this:

    url(r'^(?P<slug>[a-zA-Z0-9-]+)/$', MyView.as_view(), name = 'my_named_view')
    

    then the slug will be available inside your view functions (such as 'get_queryset') like this:

    self.kwargs['slug']
    
    0 讨论(0)
提交回复
热议问题