Я пытаюсь выяснить Django аутентификацию по умолчанию, и когда я вхожу с правильными учетными данными, это дает мне эту ошибку
NoReverseMatch at /account/login/
Reverse for 'dashboard' not found. 'dashboard' is not a valid view function or pattern name.
Request Method: POST
Request URL: http://127.0.0.1:8000/account/login/
Django Version: 2.2
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'dashboard' not found. 'dashboard' is not a valid view function or pattern name.
Exception Location: C:\Users\nouma\Desktop\social_website\myenv\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 660
Я видел некоторые подобные проблемы, но не мог понять, что именно моя проблема Я запутался с понятием реверс не найден . Вот мои views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.contrib.auth import authenticate, login
from .forms import LoginForm
from django.contrib.auth.decorators import login_required
# Create your views here.
def user_login(request):
if request.method == 'POST':
form = LoginForm(data=request.POST)
if form.is_valid():
cd = form.cleaned_data
user = authenticate(request, username=cd['username'], password=cd['password'])
if user is not None:
if user.is_active:
login(request, user)
return HttpResponse('Authenticated successfully')
else:
return HttpResponse('Disabled account')
else:
return HttpResponse('Invalid login')
else:
form = LoginForm()
return render(request, 'account/login.html', {'form': form})
@login_required
def dashboard(request):
return render(request, 'account/dashboard.html', {'section': 'dashboard'})
вот мои основные urls.py проекта
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('account/', include('django.contrib.auth.urls')),
path('account/', include('account.urls', namespace='account')),
]
urls.py приложения с именем учетная запись
from django.urls import path
from . import views
from django.contrib.auth import views as auth_views
app_name = 'account'
urlpatterns = [
# login view
# path('login/', views.user_login, name='user_login'),
path('login/', auth_views.LoginView.as_view(), name='login'),
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
path('', views.dashboard, name='dashboard'),
]
My dasboard. html
{% extends 'base.html' %}
{% block title %}Dashboard{% endblock %}
{% block content %}
<h1>Dashboard</h1>
<p>Welcome to your dashboard</p>
{% endblock %}
login. html
{% extends "base.html" %}
{% block title %}Log-in{% endblock %}
{% block content %}
<h1>Log-in</h1>
{% if form.errors %}
<p>Your username or password didn't match. Please try again</p>
{% else %}
<p>Please, use the following form to log-in:</p>
{% endif %}
<div class="login-form">
<form action="{% url 'login' %}" method="POST">
{{ form.as_p }}
{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}" />
<p><input type="submit" value="Log-in"></p>
</form>
</div>
{% endblock %}
Я думаю, что проблема незначительна, но я не могу настроить.