login page redirect to main index page
im new to django. actually i want on correct login user it redirect to my index page. here is my login handler.
def login(request):
template = "../templates/admin/login.html"
data = {
}
user = auth.authenticate(username='aa', password='bb')
if user is not None and user.is_active:
template = "../templates/admin/index.html"
auth.login(request, user)
return render_to_response( template, data,
context_instance = RequestContext( request ) )
here is my html file of login.
<form id="FormName11" action="/login/" method="post" class="prettyformlogin" name="FormName11">
{% csrf_token %}
<table width='448' border='0' cellspacing='2' cellpadding='0'>
<tr> <td><b>Username</b></td><td><input id='username' type='text' name='username'> </td></tr>
<tr><td><b>Password</b></td><td><input id='password' type='password' name='password'></td></tr>
<tr><td></td><td><input type='submit' name='Submit' value='Login'></td>开发者_如何学Python;</tr>
thanx in advance
You need to return a HttpResponseRedirect
You need to setup Django decorators and setup the settings for it to work. Here is a link for Django Decorators https://docs.djangoproject.com/en/dev/topics/http/decorators/
Add these to your settings.py:
LOGIN_URL = '/login/' LOGIN_REDIRECT_URL = '/homepage/'
Just change the values according to your specifications. (/login/ and /homepage/ are URLs).
if you will use a default login handler - there is a default setting LOGIN_REDIRECT_URL
.
精彩评论