找不到带有关键字参数'{'PK':'的'PLAN_EDIT'的反向。1个已尝试的图案:['Palan/EDIT$'] [英] Reverse for 'plan_edit' with keyword arguments '{'pk': ''}' not found. 1 pattern(s) tried: ['palan/edit$']

查看:0
本文介绍了找不到带有关键字参数'{'PK':'的'PLAN_EDIT'的反向。1个已尝试的图案:['Palan/EDIT$']的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

找不到关键字参数为‘{’pk‘:’‘}的’PLAN_EDIT‘的反向。已尝试1个模式:[‘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>

推荐答案

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

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

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

这篇关于找不到带有关键字参数&#39;{&#39;PK&#39;:&#39;的&#39;PLAN_EDIT&#39;的反向。1个已尝试的图案:[&#39;Palan/EDIT$&#39;]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆