1024programmer Java Django’/’only homepage URL error

Django’/’only homepage URL error

I’m using Django 2.0 and now I don’t know how to make an ’empty’ url for the home page. Meaning, I want it to route web.com/ or web.com.I tried this code but it doesn’t work:

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

…and post.urls

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

When I make the request, I get the error localhost:8000:

Request URL: http:// localhost:8000/
Using the URLconf defined in myblog.urls, Django tried these URL patterns in the following order:

    Administrator/

    /

An empty path does not match any of them.

I found a workaround by setting path to an empty string on both, '' but I’m not sure if it’s recommended or what it might cause Error. Thank you very much for the help. Thank you :-).

1> Xiaozhi..:


You do not need “/” as the homepage, Just leave the path “”. However, home page 127.0.0.1:8000/ is the same as 127.0.0.1:8000. This URL pattern works for home page.

urls.py

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

and posts.urls

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

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/772204

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索