gpt4 book ai didi

python - 路径 ('accounts/' ,包括(accounts.urls)),NameError : name 'accounts' is not defined

转载 作者:行者123 更新时间:2023-12-01 01:57:06 29 4
gpt4 key购买 nike

我刚刚克隆了 ProductHunt.com 网站,在处理 url 时,我收到了名称错误的错误!当我输入“localhost:8000/accounts/signup”时,它应该带我进入一个 html 页面,这是我用于测试的!主要 urls.py 如下所示:

from django.contrib import admin
from django.urls import path, include
from products import views

urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name="home"),
path('accounts/', include(accounts.urls)),
]

因此,它会转到帐户文件夹 urls.py,如下所示: from django.urls 导入路径,包括 来自.导入 View

urlpatterns = [
path('signup', views.signup, name="signup"),
path('login', views.login, name="login"),
path('logout', views.logout, name="logout"),
]

然后转到views.py,如下所示: 从 django.shortcuts 导入渲染

def signup(request):
return render(request, 'accounts/signup.html')

def login(request):
return render(request, 'accounts/login.html')

def logout(request):
return render(request, 'accounts/signup.html')

最后我的 html 是:

{% extends 'base.html %}

{% block content %}

signup!

{% endblock %}

为什么我会收到名称错误:

  File "C:\Users\Kiran\Desktop\producthunt-project\producthunt\urls.py", line 8,
in <module>
path('accounts/', include(accounts.urls)),
NameError: name 'accounts' is not defined

帮助我,谢谢,

最佳答案

替换您的代码

urlpatterns = [
...
path('accounts/', include(accounts.urls)),
]

urlpatterns = [
...
path('accounts/', include('accounts.urls')),
]

并确保您已在安装的应用程序中添加“帐户”。

关于python - 路径 ('accounts/' ,包括(accounts.urls)),NameError : name 'accounts' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50037254/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com