用户权限

1. Enabling authertication
INSTALLED_APPS = [ ...     'django.contrib.auth', #Core authentication framework and its default models.     'django.contrib.contenttypes', #Django content type system (allows permissions to be associated with models). .... MIDDLEWARE = [ ...     'django.contrib.sessions.middleware.SessionMiddleware', #Manages sessions across requests ...     'django.contrib.auth.middleware.AuthenticationMiddleware', #Associates users with requests using sessions. ....

2. Creating users and groups
3. Setting up authentication views
#Add Django site authentication urls (for login, logout, password management)
urlpatterns += [
    path('accounts/', include('django.contrib.auth.urls')),
]
4. Template
TEMPLATES = [
    {
        ...
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        ...
login.html
# Redirect to home URL after login (Default redirects to /accounts/profile/)
LOGIN_REDIRECT_URL = '/'

logged_out.html
password_reset_form.html
password_reset_done.html
password_reset_email.html
password_reset_confirm.html
password_reset_complete.html
posted @ 2020-04-15 16:03  科德科技  阅读(149)  评论(0)    收藏  举报