我将此代码用于views.py文件
@login_required
def login_edit_page(request):
#bla bla
return render_to_response('login_edit_page.html', variables)
问题是当调用 return 时,我还必须从 URL 传递一个参数。例如 URL 是 /edit?id=1 在这个例子中我想传递 id。我怎样才能做到这一点?
这是完整的代码
@login_required
def login_edit_page(request):
if request.method == 'POST':
form = LoginEditForm(request.POST)
if form.is_valid():
login1 = _login_edit(request, form, request.GET['id'])
return HttpResponseRedirect(
'/user/%s/' % request.user.username
)
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 = LoginEditForm({
'name': name,
'url': url,
'Login_username': Login_username,
'notes': notes,
'password': password
})
variables = RequestContext(request, {
'form': form
})
login1 = _login_edit(request, form, id2)
return render_to_response('login_edit_page.html', variables)