Django ImportError at /user/login d看起来不像模块路径

gpfsuwkq  于 2023-07-01  发布在  Go
关注(0)|答案(1)|浏览(124)

我正在尝试使用django. contrib. authLoginView创建一个简单的登录页面。每当我尝试登录一个用户时,都会收到以下错误:ImportError at /user/login d doesn't look like a module path

这是我在url中激活视图的代码:

from django.urls import path
from . import views
from django.contrib.auth import views as auth_views

urlpatterns = [
    path("register", views.register_request, name="register"),
    path("login", auth_views.LoginView.as_view(template_name="user/login.html"), name="login"),
    path("logout", auth_views.LogoutView.as_view(template_name="user/logout.html"), name="logout")
]

这是我的html文件user.login.html:

{% extends "base/base.html" %}
{% load crispy_forms_filters %}

{% load crispy_forms_tags %}

{% block content %}
    <div class="content-section">
        <form method="POST" >
            {% csrf_token %}
            <fieldset class="form-group">
                <legend class="border-bottom mb-4">Log In</legend>
                    {{ form|crispy }}

            </fieldset>
            <div class="form-group">
                <button class="btn btn-outline-info" type="submit">Login</button>
            </div>
        </form>
        <div class="border-top pt-3">
            <small class="text-muted">
                Need An Account? <a class="ml-2" href="{% url 'register' %}">Sign Up Now</a>
            </small><br>
            <small class="text-muted">
                <a href="/">Forgot password?</a>
            </small>
        </div>
    </div>
{% endblock content %}

作为一个注解,logout视图工作得很好,当我在login.html中点击submit时发生错误jusr。

我已尝试将这些行添加到settings.py文件中-

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend'
)

LOGIN_URL = 'user/login'
xdnvmnnf

xdnvmnnf1#

您将AUTHENTICATION_BACKENDS定义为一个字符串-它应该是一个 iterable。所以,添加一个***逗号***使其成为可迭代的

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
                                              ^^^
)

相关问题