django Error during template rendering Reverse for 如何更新数据?

新手上路,请多包涵

django 1.9.6
python 3.6
想要修改数据
clipboard.png

出现错误
clipboard.png

url.py:
from django.conf.urls import url
from my_app import views
urlpatterns = [

url(r'^$', views.get_people, name='get_people'),
url(r'^detail/$', views.detail, name='detail'),
url(r'^delete/(?P<people_id>\d+)$', views.delete, name='delete'),
url(r'^edit/(?P<people_id>\d+)/$', views.edit, name='edit')

]
views:
def edit(request,people_id):

if request.method == 'GET':
    people = get_object_or_404(People,pk=people_id)
    form = Form(initial={'name': people.name, 'phone': people.phone})
    return render(request, 'edit.html', {'form': form})
else:
    form = Form(request.POST)
    if form.is_valid():
        People.objects.filter(pk=people_id).update(**form.cleaned_data)
        return HttpResponseRedirect(reverse('detail'))
    return render(request, 'edit.html', {'form': form })

html:

    <tbody>
    {% for people in people_list %}
        <tr>
            <td>{{ people.name }}</td>
            <td>{{ people.phone }}</td>
            <td>
                <a href="{% url 'delete' people.id %}">删除</a>
                <a href="{% url 'edit' people.id %}">修改</a>
            </td>

        </tr>
    {% endfor %}
    </tbody>

菜鸟没什么办法,求帮助

阅读 2.5k
1 个回答

你应该把edit.html的代码贴出来,里面肯定有某个地方
{% url 'edit' people.id %} people.id没传值

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏