Django 1.9 get kwargs in class based view
<p>I was wondering if there is a way to get the kwargs directly in a class based view. I know this can be done in functions inside the class, but I'm having problems when I try this:</p>

<p><strong>views.py</strong></p>

<pre><code>class EmployeesUpdateStudies(UpdateView):
    form_class = form_ES
    model = EmployeePersonal
    template_name = 'employeesControll/employees_studies_update_form.html'
    success_url = reverse('employee-details',  kwargs={'pk': kwargs.get('pk')})
</code></pre>

<p>My <em>url</em> is the following</p>

<pre><code>url(r'^employees/detalles/(?P&lt;pk&gt;[0-9]+)/$', login_required(views.EmployeeDetails.as_view()), name='employee-details')
</code></pre>

<p>You can't use <code>kwargs</code> in <code>success_url</code>, because when Django loads the class when the server starts, it doesn't have access to the request. Override the <code>get_success_url</code>  method instead. </p>

<pre><code>def get_success_url(self) 
    return reverse('employee-details', kwargs={'pk': self. kwargs['pk']})
</code></pre>

python django django-views django-urls