登录页面重定向到主索引页面 [英] login page redirect to main index page

查看:159
本文介绍了登录页面重定向到主索引页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是django的新手。
实际上我想在正确的登录用户上将其重定向到我的索引页面。
是我的登录处理程序。

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 ) )






这是我登录的HTML文件。


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></tr>






预先感谢


thanx in advance

推荐答案

您需要设置Django装饰器并对其进行设置。这是Django Decorators的链接 https://docs.djangoproject.com/en / dev / topics / http / decorators /

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/

将这些添加到您的settings.py:

Add these to your settings.py:

LOGIN_URL ='/ login /'
LOGIN_REDIRECT_URL ='/ homepage /'

LOGIN_URL = '/login/' LOGIN_REDIRECT_URL = '/homepage/'

只需根据您的规范更改值。 (/ login /和/ homepage /是URL)。

Just change the values according to your specifications. (/login/ and /homepage/ are URLs).

这篇关于登录页面重定向到主索引页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆