i use this code to views.py file
@login_required
def login_edit_page(request):
#bla bla
return render_to_response('login_edit_page.html', variables)
the problem is that when the return is called, i have to also pass an argument from the URL. for example the URL is /edit?id=1 in this example i want to pass the id. how can i do that?
this is the full code
@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)
You can not use
render_to_responsethe way you do. Try this:Note, that I added
id2to context dict, so it is reachable in the template by{{ id }}. Also, checkout how I retrieve url parameter from request.Another approach is to reach url parameter directly from
request(as Mark Lavin noticed, it will work in case ofdjango.core.context_processors.requestis present inTEMPLATE_CONTEXT_PROCESSORS):But sincerely, you should make your view more clean, there are a lot of problems in it.