Django '/' only homepage url error

天涯浪子 提交于 2019-12-05 05:36:39

You don't need "/" for Home url, just leave both the path with "". The home url 127.0.0.1:8000/ is nevertheless is same as 127.0.0.1:8000. This URL pattern will work for the home page.

urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('post.urls'))
]

and posts.urls

urlpatterns = [
    path('', views.index, name='index')
]

There are plenty of references to blank URL patterns in the Django 2.0 doccumentation.

Django 2.0 Docs URLs section

Furthermore, the slash you added on 'admin/' when viewing from browser is not required. The url dispatcher will strip the trailing slashes on your URL confs, but it wont be stripped on the Web request. This means it wont find a match in your case, try localhost:8000/admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!