思路:
主index显示
server01 修改 删除
server02 修改 删除
server03 修改 删除
点击(修改)
templates中 <a href="//www.greatytc.com/rectify_people-{{people.id}}">修改</a>
=======================>
urls.py
url(r'^rectify_people-(?P<people_id>\d+)', views.rectify_people, name='rectify_people'),
========================>
views.py
def rectify_people(request, people_id):
**********************************************************************
??????????????????????????先不填
**********************************************************************
people = models.People.objects.filter(id=people_id).first()
return render(request, 'app01/tt.html', {'people': people})
=====================================>
templates/app01/tt.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="post" action="/app01/rectify_people-{{ people.id }}">
{% csrf_token %}
<input type="text" name="username" placeholder="username" value="{{ people.username }}">
<input type="text" name="password" placeholder="password" value="{{ people.password }}">
<input type="submit" value="submit">
</form>
</body>
</html>
==========================================>
又通过urls.py
url(r'^rectify_people-(?P<people_id>\d+)', views.rectify_people, name='rectify_people'),
==========================================>
views.py(同上的views.py)
def rectify_people(request, people_id):
**********************************************************************
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
models.People.objects.filter(id=people_id).update(username=username, password=password)
return redirect('/app01/')
**********************************************************************
people = models.People.objects.filter(id=people_id).first()
return render(request, 'app01/tt.html', {'people': people})
到此OK