18910140161

python-django-help!导致404错误堆栈溢出的settings.py、urls.py和views.py

顺晟科技

2022-10-19 11:54:56

101

最近,我在运行Django项目时遇到了一个404错误。不知为什么我想不通,我需要帮助。我对django和一般编码都是新手。它以前是工作的,我不知道我做错了什么。 以下是错误

Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:

admin
index.html [name='index']
experience.html [name='experience']
projects.html [name='projects']
research.html [name='research']
education.html [name='education']
404.html [name='comeback']
design.html [name='design']
The empty path didn’t match any of these.

以下是程序代码。

下面是views.py

Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:

admin
index.html [name='index']
experience.html [name='experience']
projects.html [name='projects']
research.html [name='research']
education.html [name='education']
404.html [name='comeback']
design.html [name='design']
The empty path didn’t match any of these.

以下是urls.py(app)

Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:

admin
index.html [name='index']
experience.html [name='experience']
projects.html [name='projects']
research.html [name='research']
education.html [name='education']
404.html [name='comeback']
design.html [name='design']
The empty path didn’t match any of these.

这里是urls.py(其中设置是)

Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:

admin
index.html [name='index']
experience.html [name='experience']
projects.html [name='projects']
research.html [name='research']
education.html [name='education']
404.html [name='comeback']
design.html [name='design']
The empty path didn’t match any of these.

以下是设置。py

Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:

admin
index.html [name='index']
experience.html [name='experience']
projects.html [name='projects']
research.html [name='research']
education.html [name='education']
404.html [name='comeback']
design.html [name='design']
The empty path didn’t match any of these.

以下是使用

时出现的新错误
Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:

admin
index.html [name='index']
experience.html [name='experience']
projects.html [name='projects']
research.html [name='research']
education.html [name='education']
404.html [name='comeback']
design.html [name='design']
The empty path didn’t match any of these.

复制/粘贴视图中出错

Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:

admin
index.html [name='index']
experience.html [name='experience']
projects.html [name='projects']
research.html [name='research']
education.html [name='education']
404.html [name='comeback']
design.html [name='design']
The empty path didn’t match any of these.

转到http://127.0.0.1:8000/admin有效,但转到http://127.0.0.1:8000/eduction

等其他页面时,我会得到上面相同的属性错误

更新- 到目前为止,除了《家》之外,我还有所有的页面要写。 以下是临时修复程序

urls.ps

Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:

admin
index.html [name='index']
experience.html [name='experience']
projects.html [name='projects']
research.html [name='research']
education.html [name='education']
404.html [name='comeback']
design.html [name='design']
The empty path didn’t match any of these.

下面是views.py

Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:

admin
index.html [name='index']
experience.html [name='experience']
projects.html [name='projects']
research.html [name='research']
education.html [name='education']
404.html [name='comeback']
design.html [name='design']
The empty path didn’t match any of these.


顺晟科技:

这是因为您的主URL不匹配。如果您的网站是localhost:8000,并且您正在访问相同的url路径,则将显示404 not found,因为您还没有为主页添加路径。所以:

app.urls

Using the URLconf defined in portfolio.urls, Django tried these URL patterns, in this order:

admin
index.html [name='index']
experience.html [name='experience']
projects.html [name='projects']
research.html [name='research']
education.html [name='education']
404.html [name='comeback']
design.html [name='design']
The empty path didn’t match any of these.

并且视图中应该有home函数来呈现某个页面,就像您对其他路由所做的那样。

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航