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') ]