NameError:未定义名称“ ProfileView”

问题描述

当尝试运行服务器即时通讯时 path(“ accounts”,ProfileView.as_view(template_name =“ profile.html”)), NameError:名称“ ProfileView”未定义

#APPS / ACCOUNTS / URLS

nodeEnter.append('text')
    .attr('width',"10px" ).attr('height',"10px" ) // this will set the height and width
    .attr("class","fas fa-adjust") // Font Awesome class,any
    .attr("x",15) // for placement on x axis
    .attr("y",-5); // for placement on y axis

#websiteproject / views.py

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

from . import views

app_name="accounts"
urlpatterns = [
    path("accounts",ProfileView.as_view(template_name="profile.html")),#Django-AUTH
    path(
        "login",auth_views.LoginView.as_view(template_name="accounts/login.html"),name="login"
    ),path("logout",auth_views.logoutView.as_view(),name="logout"),]

解决方法

views.ProfileView.as_view()看起来像是基于类的视图实现。 此外,我在ProfileView

中看不到views.py

作为参考,请查看类SendMessage并在URL中查看

,

代码已更正,服务器正常运行,并且显示profile.html的网站/帐户/配置文件

[1823742]

#URLS

{% block content %}
<h1>
    {{user.username}} Profile
</h1>
{% endblock %}

#VIEWS.PY

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

from weedmanweeds.views import ProfileView

app_name="accounts"
urlpatterns = [
    path("profile",ProfileView.as_view(template_name="accounts/profile.html"),name="profile"),#Django-AUTH
        path(
            "login",auth_views.LoginView.as_view(template_name="accounts/login.html"),name="login"
        ),path("logout",auth_views.LogoutView.as_view(),name="logout"),]