0
I’m trying to use Django’s libraries to check if the user is logged in, and only then can he log into the pages of my website.
I’m coding according to some Internet classes, in his example was functional, and he showed an error, asking register/login.html
, then he created directory template/register/login.html
so to check if the user is logged in, and if not, open a login screen.
I appreciate any kind of help, indication, or improvement in my code.
Main folder of the project, py..
from django.contrib import admin
from django.urls import path,include
from clientes import urls as clientes_urls
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views
urlpatterns = [
path('clientes/', include(clientes_urls)),
path('login/', auth_views.auth_login, name='login'),
path('logout/', auth_views.auth_logout, name='logout'),
path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
#Templates
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Edit 1: There is none def
, in the py views., calling any 'login' directory (either by html, function or Django library), both in my code and in the code I am basing myself on.