TypeError at:/ __init __()接受1个位置参数,但给出了2个

时间:2019-07-19 06:13:11

标签: python django

我是学习Django的新手,尝试运行服务器时出现此错误:  # ⇓⇓ THIS (\.\s*)(?=expect) 网址:

__init__() takes 1 positional argument but 2 were given

这是我的观点:

from django.contrib import admin
from django.urls import path
from users import views as user_views
from main.views import about, ListView
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
    path('admin/', admin.site.urls),
    path('register/', user_views.register, name='register'),
    path('profile/', user_views.profile, name='profile'),
    path('about/', about, name='about'),
    path('', ListView, name='PostListViews'),
    path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
    path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

我不知道错误是从哪里来的,请事先向我解释,并谢谢:)

1 个答案:

答案 0 :(得分:2)

代替

path('', ListView, name='PostListViews'),

path('', PostListViews.as_view(), name='PostListViews'),

尝试