我試圖從URL中獲取兩個參數以添加到我的上下文中。從URL中獲取參數slugs
這是網址:
url(r'^company/(?P<company>[\w\-\_]+)/?/(?P<program>[\w\-\_]+)/?$', RegistrationView.as_view(),
name='test'),
的觀點:
class RegistrationView(RegistrationMixin, BaseCreateView):
form_class = AppUserIntroducerCreateForm
template_name = "registration/register_introducer.html"
slug_field = 'company'
def get_context_data(self, *args, **kwargs):
context = super(RegistrationIntroducerView, self).get_context_data(**kwargs)
print(self.get_slug_field())
context['company'] = ??????
context['program'] = ??????
return context
我想盡一切辦法獲取值self.company
,kwargs['company']
等等,我有什麼錯我在這裏幹什麼?
self.kwargs是要走的路。一個例子是在這裏:http://stackoverflow.com/questions/6629426/django-class-based-generic-views-and-authentication – mawimawi