在genric视图中得到了一个意想不到的关键字参数'pk'

时间:2017-08-17 09:18:49

标签: python django django-generic-views

我正在尝试使用内置UpdateView& DeleteView,我一直在使用Exception Value获取TypeErrors:

  

get()得到了一个意外的关键字参数'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

模板

<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>

1 个答案:

答案 0 :(得分:1)

您在SampleUpdate中使用的是urls.py,但我无法在您views.py的任何地方看到该课程,而是SeqRunUpdate&amp; SeqRunDelete。在您的网址中使用相应的视图类,错误应该消失。