完全记录的网站Django

时间:2015-02-03 03:08:19

标签: django login

我使用django-stronghold

太过我的网站了。

请参阅我的代码:

settings.py

INSTALLED_APPS = (
    ...
    'stronghold',
)

MIDDLEWARE_CLASSES = (
    ...
    'stronghold.middleware.LoginRequiredMiddleware',
)

STRONGHOLD_PUBLIC_URLS = (
    '/admin/',
)

views.py

...
from stronghold.decorators import public
...

@public
def index(request):
    return render(request, 'index.html')

@public
def about(request):
    return render(request, 'about.html')

class PersonList(ListView):
    pass

class PersonDetail(DetailView):
    pass

class PersonForm(CreateView):
    pass

urls.py

...
    url(r'^admin/', include(admin.site.urls), name='admin'),

但是当我点击需要登录的链接时,如何重定向到登录页面?重定向到/ admin /

因为未登录时其余页面返回404.

1 个答案:

答案 0 :(得分:0)

LOGIN_URL = '/admin/'添加到 settings.py