gpt4 book ai didi

python - 在通用 View 上收到意外的关键字参数 'pk'

转载 作者:行者123 更新时间:2023-12-01 02:40:51 25 4
gpt4 key购买 nike

我正在尝试使用内置的 UpdateViewDeleteView,并且我不断收到 TypeErrors,异常值:

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

模板

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

最佳答案

您在 urls.py 中使用 SampleUpdate,但我在 views.py 中的任何位置都看不到该类,而是您有SeqRunUpdateSeqRunDelete。在您的网址中使用相应的 View 类,错误就会消失。

关于python - 在通用 View 上收到意外的关键字参数 'pk',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45731151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com