Django @login_required无效

时间:2016-05-19 13:53:07

标签: django

我在django中学习登录身份验证并使用@login_required装饰器来防止人员在登录前看不到页面内容但它无法正常工作。

view.py

from django.contrib.auth.decorators import login_required

@login_required
def dashboard(request):
    return render(request, 'login/dashboard.html')

urls.py

app_name='login'
urlpatterns=[
    # html urls
    url(r'^$',views.index),
    url(r'^login_form/$',views.login_form),
    url(r'^dashboard/$',views.dashboard),
    url(r'^profile/$',views.profile),
    url(r'^logout/$',views.logout),
]

setting.py

LOGIN_URL = '/login_form/'

dashboard.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Dashboard</title>
</head>
<body>
{% verbatim %}
<h1>Username: {{ username }}</h1>
<h1>Token: {{ token }}</h1>
<button type="button" class="" ng-click="logout()">logout</button>
{% endverbatim %}

<a href="#profile">see profile</a>
</body>
</html>

0 个答案:

没有答案