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>Alasdair's answer solves your problem. You can however define a <code>get_absolute_url</code>  method for your <code>EmployeePersonal</code> model which will act as the <code>success_url</code> for your view: </p>

<blockquote>
  <p>You donât even need to provide a <code>success_url</code> for <code>CreateView</code> or
  <code>UpdateView</code> - they will use <code>get_absolute_url()</code> on the model object
  if available.</p>
</blockquote>

<p>You'll use <code>self.id</code> in the <code>get_absolute_url</code> method for the model objects primary key.</p>

<hr>

<p>Reference:</p>

<p><a href="https://docs.djangoproject.com/en/1.10/topics/class-based-views/generic-editing/#model-forms" rel="nofollow">Model Forms</a></p>

python django django-views django-urls