我正在Django项目中创建一个基本应用程序。我将视图映射到url。运行此项目时显示
找不到404页。
from django.urls import path
from . import views
urlpatterns=[
path(' ',views.index,name="index"),
]
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse("hello world");
from django.urls import include,path
from django.contrib import admin
urlpatterns = [
path("myapp/ ",include('myapp.urls')),
path('admin/', admin.site.urls),
]
我希望输出像世界一样enter image description here
答案 0 :(得分:0)
从模式中删除空格字符
在urls.py
中进行更改
path(' ',views.index,name="index")
至path('',views.index,name="index")
在project/urls.py
中进行更改
path("myapp/ ",include('myapp.urls')),
至path("myapp/",include('myapp.urls')),