I try to dynamically call a view in Django with this url configuration :
url(r'^niveau/(?P<niveau_id>\d+)/(?P<channel>\w+)/$', views.switcher , name='vue_niveau')
Then in my view.py, i have :
def switcher(request, niveau_id, channel):
if channel == 'VueNiveau':
return VueNiveau.as_view()(request)
It works, as i get the good view call, but then when i try to get the niveau_id in my VueNiveau context :
class VueNiveau(generic.TemplateView):
template_name = 'cours/vue_niveau.html'
...
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
niveau = Niveau.objects.get(id=kwargs['niveau_id'])
context['niveau'] = niveau
i get a KeyError, saying that niveau_id is undefined...
Without the switcher function, all works perfectly and i can get the url data etc... So it seems like something is happening between the call of the switcher function and get_context_data...
Does someone understand this behaviour ?