如何解决Django urlconfig模式中的404错误

时间:2019-04-12 19:27:38

标签: python django

我正在Django项目中创建一个基本应用程序。我将视图映射到url。运行此项目时显示

  

找不到404页。

在urls.py

from django.urls import path
from . import views
urlpatterns=[
    path(' ',views.index,name="index"),
]

在views.py

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
def index(request):
    return HttpResponse("hello world");

在project / urls.py

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

1 个答案:

答案 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')),