In the Django's tutorial, I created an app name front, and its urls.py definition like this:

from django.contrib import admin
from django.urls import path, include

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

So, if the app's url in web browser is http://127.0.0.1:8000/front/
In fact, most website the home page won't have subdirectory. So, the solutions is here:

from django.contrib import admin
from django.urls import path, include, re_path

urlpatterns = [
    re_path(r'^', include('front.urls')),
    path('front/', include('front.urls')),
    path('admin/', admin.site.urls),
]

Now, you can visit the app root url in the home page. http://127.0.0.1:8000/

标签: python, django

相关文章

添加新评论