当我使用 url 中的 id 参数编辑记录,并且正在使用“elif 'id' in request.GET:”时,它不会更新记录,但会创建一个新行
@login_required
def login_save_page(request):
if request.method == 'POST':
form = LoginSaveForm(request.POST)
if form.is_valid():
# Create or get login.
login1 = _login_save(request, form)
return HttpResponseRedirect(
'/user/%s/' % request.user.username
)
elif 'id' in request.GET:
id2 = request.GET['id']
name=''
url=''
Login_username =''
notes= ''
password=''
try:
login1 = login.objects.get(
id = id2,
username=request.user
)
name = login1.name
url = login1.loginUrl
Login_username = login1.login_username
notes = login1.notes
password = login1.password
except (login.DoesNotExist):
pass
form = LoginSaveForm({
'id': id2,
'name': name,
'url': url,
'Login_username': Login_username,
'notes': notes,
'password': password
})
else:
form = LoginSaveForm()
variables = RequestContext(request, {
'form': form
})
return render_to_response('login_save_page.html', variables)