django 1.9.6
python 3.6
想要修改数据
出现错误
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>
菜鸟没什么办法,求帮助
你应该把edit.html的代码贴出来,里面肯定有某个地方
{% url 'edit' people.id %} people.id没传值