我刚开始学习Django,就出现了以下错误。
[![The site doesn't see URL and then Error 404][1]][1]
urls.py - site
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('webexample/', include ('webexample.urls')),
]
urls.py - webexample
from django.urls import path
from . import views
urlpatterns = [
path(r'^$', views.index, name='index'),
]
views.py - webexample
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("<h3>This page isn't set up yet...</h3>")
把路径改成这个,就可以使用当前的url了。
path(r'', views.index, name='index')
你可以这样做
path('index/', views.index, name='index'),
或
re_path(r'^index/$', views.index, name='index'),
要想知道更多关于这方面的知识,你可以参考django doc https:/docs.djangoproject.comen3.0refurls。