gpt4 book ai didi

python - 使用关键字参数 'plan_edit' pk' : '{' '' palan/edit$'] 反转 }' not found. 1 pattern(s) tried: ['

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

我收到以下错误:

Reverse for 'plan_edit' with keyword arguments '{'pk': ''}' not found. 1 pattern(s) tried: ['palan/edit$']`.

有谁知道怎么解决吗?

urls.py

urlpatterns = [
url(r'^$', views.post_list, name='post_list'),
url(r'^palan/(?P<pk>[0-9]+)/$', views.palan_detail, name='palan_detail'),
url(r'^palan/new/$', views.plani_new, name='plani_new'),
url(r'^nn1/new/$', views.plani_new1, name='plani_new1'),
url(r'^palan/edit$', views.edit, name='plan_edit'),
]

views.py

def edit(request, pk):
post = get_object_or_404(Planning, pk=pk)
if request.method == "POST":
form = PostFormP(request.POST, instance=post)
if form.is_valid():
post = form.save(commit=False)
post.author = request.user
post.published_date = timezone.now()
post.save()
return redirect('palan_detail', pk=post.pk)
else:
return render(request, 'pages/plan_edit.html')

def palan_detail(request, pk):
palan = get_object_or_404(Planning, pk=pk)
j = Jour.objects.all().count()
return render(request, 'pages/palan_detail.html', {'palan': palan, 'j':j},)

palan_detail.html

<a href="{% url 'plan_edit' pk=post.pk %}">
<h1>{{ palan.parcours }}</h1>
</a>
<p>{{ palan.semestre|linebreaksbr }}</p>
<p>{{ palan.jour.jour1}}</p>

最佳答案

您的 View 中没有名为 post 的上下文变量。更改以下行

<a href="{% url 'plan_edit' pk=post.pk %}">

<a href="{% url 'plan_edit' pk=palan.pk %}">

关于python - 使用关键字参数 'plan_edit' pk' : '{' '' palan/edit$'] 反转 }' not found. 1 pattern(s) tried: [',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50574940/

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