问题:
WARNINGS:
?: (2_0.W001) Your URL pattern '^$' [name='index'] has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().
?: (2_0.W001) Your URL pattern '^admin/' has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().
教程源程序文件:
Learning_log.urls:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'', include('learning_logs.urls', namespace='learning_logs')),
]
Learning_logs.urls:
"""定义learning_logs的URL模式"""
from django.conf.urls import url
from . import views
urlpatterns = [
# 主页
url(r'^$', views.index, name='index'),
]
网页显示如下:
Page not found (404)
| Request Method: | GET |
| Request URL: | http://localhost:8000/ |
Using the URLconf defined in learning_log.urls, Django tried these URL patterns, in this order:
- admin/
- ^$ [name='index']
The empty path didn’t match any of these.
You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
更改过后的文件:
Learning_log.urls:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path(r'admin/', admin.site.urls),
path(r'', include(('learning_logs.urls', 'learning_logs'), namespace='learning_logs')),
]
Learning_logs.urls:
from django.urls import path
from . import views
urlpatterns = [
path(r'', views.index, name='index')
]
网页显示如下:
Learning Log
Learning Log helps you keep track of your learning, for any topic you're learning about.
达到预期目的!其中正则表达式参数留空是何道理,还不清楚。



