Django class view: __init__
问题 I want to get <Model> value from a URL, and use it as an __init__ parameter in my class. urls.py url(r'^(?P<Model>\w+)/foo/$', views.foo.as_view(), name='foo_class'), views.py class foo(CreateView): def __init__(self, **kwargs): text = kwargs['Model'] # This is not working text = kwargs.get('Model') # Neither this Bar(text) ... Clearly, I'm missing something, or my understanding of URL <> class view is wrong. 回答1: You should override dispatch method for such use cases. class Foo(CreateView):