我正在尝试实施SayHello
应用页面。这是我的urls.py内容
from django.urls import path
from hello.views import myView
urlpatterns = [
path('admin/', admin.site.urls),
path('sayHello/',myView),
]
将此应用添加到URL后,“ http://127.0.0.1:8000/sayHello/”可以正常工作。
但是'http://127.0.0.1:8000/'向我报告了以下404错误页面。
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in editdojo_project.urls, Django tried these URL patterns, in this order:
admin/
sayHello/
The empty path didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
如何解决此错误?
答案 0 :(得分:4)
这是因为您没有与首页相匹配的路由(urls.py文件中为空字符串),例如,如果您这样做,您将在'http://127.0.0.1:8000/中看到相同的HelloWorld '
<button type="button" class="btn btn-primary"
data-toggle="modal" data-target="#modal-body-id">
答案 1 :(得分:3)
bcoz django首先在urls.py中找到相应的url模式,然后从views.py文件中启动视图... path('admin /',admin.site.urls)将u移至http://127.0.0.1:8000/admin,path('sayHello /',myView)将u移至http://127.0.0.1:8000/sayHello 但是在urls.py中,您没有与http://127.0.0.1:8000/匹配的网址-通常是索引页或首页, 添加索引做到这一点->
urlpatterns = [
path('admin/', admin.site.urls),
path('sayHello/',myView),
path('',view),
]
答案 2 :(得分:1)
尝试
<nav class="pagination col-md-12">
<ul class="pagination__list">
<li><a rel="prev" href="#" class="pagination__previous btn-squae disable">‹</a></li>
<li><span class="pagination__page btn-squae active">1</span></li>
<li><a href="#" class="pagination__page btn-squae">2</a></li>
<li><a href="#" class="pagination__page btn-squae">...</a></li>
<li><a href="#" class="pagination__page btn-squae">14</a></li>
<li><a rel="next" href="#" class="pagination__next btn-squae">›</a></li>
</ul>
</nav>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
希望有帮助