aviv aviv - 9 months ago 77
Python Question

got an unexpected keyword argument 'pk' on genric view

I am trying to use Built-in

UpdateView
&
DeleteView
, And I am keep getting TypeErrors, with the Exception Value:


get() got an unexpected keyword argument 'pk'


views.py

class SeqRunUpdate(LoginRequiredMixin, UpdateView):
form_class = Sequencing_RunsForm
model = Sequencing_Runs

class SeqRunDelete(LoginRequiredMixin, DeleteView):
model = Sequencing_RunsForm
success_url = reverse_lazy('seq_run-private')


urls.py

url(r'^private/Samples/(?P<pk>[0-9]+)/$', views.SampleUpdate.as_view(), name='sample-update'),
url(r'^private/Samples/(?P<pk>[0-9]+)/del$', views.SampleUpdate.as_view(), name='sample-delete'),


models.py

class Sequencing_Runs(models.Model):
seq = models.CharField (max_length=250, unique=True, verbose_name='Sequence')
date= models.DateField (auto_now=False, verbose_name='Date')
classifaction = models.IntegerField(choices=CLASSIFACTION_CHOICES, default=1)

def get_absolute_url(self):
return reverse('table:seq_run-add')

def __str__(self):
return self.seq


Template

<td><form action="{% url 'table:seq_run-update' seq.pk %}" method="get" style="display: inline;">
{% csrf_token %}
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-edit"></span>
</button>
</form></td>
<td><form action="{% url 'table:seq_run-delete' seq.pk %}" method="get" style="display: inline;">
{% csrf_token %}
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-trash"></span>
</button>
</form></td>

Answer Source

You are using SampleUpdate in your urls.py but I can't see that class anywhere in your views.py, you instead have SeqRunUpdate & SeqRunDelete. Use the respective view class in your urls and the error should go away.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download