0

我写了一个关于登录的函数。如下所示:

def login(request,template_name="login/login.html"):

    res = {}
    if(request.method == "POST"):
        username = request.POST.get('username')
        password = request.POST.get('password')

        user = auth.authenticate(username=username,password=password)

        if user is not None:
            if user.is_active:
                auth.login(request,user)
                redirect_to = reverse("home")
                return HttpResponseRedirect(redirect_to)

    return render_to_response(template_name,RequestContext(request,res))

如果登录检查成功,它会重定向到我的主页。我的问题是,它显示了正确的页面内容。但网址是错误的。它留在登录网址上。

如何显示重定向页面 URL?

HTML代码是:

<form class="authenticate" action="{{ next }}" method="post">
    {% csrf_token %}
    <table border="0">
        {{ login_form }}
    </table>
    <input type="hidden" name="action" value="login" />
    <input type="hidden" name="next" value="{{ next }}" />
    <input type="submit" id="login-btn" value="login" />
</form>

urls.py 是:

urlpatterns = patterns('',
url(r'^$','mypro.views.home',name='home'),
url(r'^login/',include('login.urls')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)


urlpatterns = patterns('',
url(r'^$','login.views.login',name="login"),
url(r'^logout/$','login.views.logout',name="logout"),
 )

我发现萤火虫的响应和 html 都显示“重新加载页面以获取源代码:http://xx.xx.xx.xx:8002/h5acr/login/refresh/ ”。如何重新加载页面?

4

1 回答 1

0

在您的登录表单中,操作应该是登录 url,而不是next.

<form class="authenticate" action="{% url 'login' %}" method="post">
于 2013-11-01T09:37:25.420 回答