Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未找到Django 2.0.5 404错误页面_Python_Django_Python 3.x - Fatal编程技术网

Python 未找到Django 2.0.5 404错误页面

Python 未找到Django 2.0.5 404错误页面,python,django,python-3.x,Python,Django,Python 3.x,我在使用Django方面是新手,我遇到了一些问题。当我运行我的服务器“runserver”时,它显示404页未找到。我的项目目录名为“mysite”,我的应用程序名为“webapp”。我认为问题出在“URL”文件中。我还将我的应用程序名放在“设置”部分的“已安装的应用程序”中 这是mysite/url.py文件中的代码: """mysite URL Configuration The `urlpatterns` list routes URLs to views. For more info

我在使用Django方面是新手,我遇到了一些问题。当我运行我的服务器“runserver”时,它显示404页未找到。我的项目目录名为“mysite”,我的应用程序名为“webapp”。我认为问题出在“URL”文件中。我还将我的应用程序名放在“设置”部分的“已安装的应用程序”中

这是mysite/url.py文件中的代码:

"""mysite URL Configuration

 The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import:  from my_app import views
2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
1. Add an import:  from other_app.views import Home
2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('admin/', admin.site.urls),
    path('webapp', include("webapp.urls")),
]
from django.urls import path
from . import views
urlpatterns = [
    path('', views.index, name = "index"),
]
这是webapp/url.py文件中的代码:

"""mysite URL Configuration

 The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import:  from my_app import views
2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
1. Add an import:  from other_app.views import Home
2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('admin/', admin.site.urls),
    path('webapp', include("webapp.urls")),
]
from django.urls import path
from . import views
urlpatterns = [
    path('', views.index, name = "index"),
]
我使用的是最新的Django版本2.0.5,我曾尝试查找此错误,但其中大多数似乎都是Django的旧版本


在此问题上,我将非常感谢您的帮助。

在您的webapp/url.py中,您必须指定应用程序名称,如
app\u name=“webapp”

mysite/url

urlpatterns = 
    [
        path('webapp/'), include() )
    ]
注意:父URL必须包含尾部斜杠

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

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

您忘记在路径“webapp/”中的webapp之后添加反斜杠,这将有助于重定向到视图中的其他方法。

由于您的根URL没有定义任何内容,因此它是空的,并出现404错误。要解决此问题,只需在地址栏中的本地服务器URL之后键入视图路径。即“127.0.0.1:8000/webapp”或使用“localhost/name\u of_url”

@mahir,请在webapp/根/url中添加尾部,现在您可以访问服务器/webapp