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:



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 is the same as This URL pattern works for home page.


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


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