Your code is fine, the only problem is that in the form you are passing the next attribute as a post because the method is post. In the views you try to get the next parameter within the get dictionary which is obvious not there.
You have to declare the html form action like this in order to your views work.
{% if next %}
<form action="/login/?next={{next}}" method="post" >
{%else%}
<form action="/login/" method="post" >
{% endif %}
{% csrf_token %}
username:
<input type="text" name="username" value="{{ username }}" /><br />
password:
<input type="password" name="password" value="" /><br />
<input type="submit" value="Log In"/>
{% debug %}
</form>
There, if there is a next variable then you include in the url for retrieve it as a get parameter. If not, the form doesn’t include it.
This is the best approach, but you may also fix this in your views by requesting the next from the POST dictionary like this:
return HttpResponseRedirect(request.POST.get('next'))
Note that this will only work if the template account_login has a variable called next. You should generate it in the views and pass it to the template when you render it.
Normally, in the template you would do something like this:
# this would be hardcoded
next="/issueapp/1628/view/22"
# you may add some logic to generate it as you need.
and then you do:
return render_to_response(
'account_login.html',
{
'state':state,
'username': username,
'next':next
},
context_instance=RequestContext(request)
)
Hope this helps!