为什么我无法在 DetailView 中访问从 url 字符串传递的 kwargs['party_id']?
Test url: http://127.0.0.1:8000/party/3/activity/2/
网址.py
url(r'^party/(?P<party_id>\d*)/activity/(?P<pk>\d*)/$', ActivityView.as_view(), name='activity')
视图.py
class ActivityView(DetailView):
template_name = "ooe/activity_results.html"
context_object_name = "activity"
model = Activity
def get_context_data(self, **kwargs):
context = super(ActivityView, self).get_context_data(**kwargs)
#this line is not working because kwargs is just: {'object': <Activity: Activity 2>}
context['submissions'] = self.get_object().get_submissions(kwargs['party_id'])
return context
@method_decorator(user_passes_test(active_participant))
def dispatch(self, *args, **kwargs):
return super(ActivityView, self).dispatch(*args, **kwargs)