Reputation: 601
I have the following code
---- urls.py ----
url(r'^(?P<city_slug>[-\w]+)/$',
BookingWizard.as_view(),
name='city_booking'),
---- views.py ----
class BookingWizard(SessionWizardView):
def get_context_data(self, form, **kwargs):
context = super(BookingWizard, self).get_context_data(form, **kwargs)
cities = City.objects.all()
context.update({'cities': cities,
'city': City.objects.get(slug=kwargs['city_slug'])})
return context
The problem is I'm getting key error trying to access kwargs['city_slug']
in the get_context_data()
method.
although I can access kwargs['city_slug']
in the done()
method with no problems.
Any ideas?
Upvotes: 4
Views: 2373
Reputation: 976
You can access the kwargs using self.kwargs
. This is because it gets set in the as_view()
method of View
which is a superclass of SessionWizardView
.
https://github.com/django/django/blob/master/django/views/generic/base.py#L61-68
Upvotes: 6