[英]Page 404 error after running Django server
I have just started learning django and was trying to make a smartnotes App project by following a course.我刚刚开始学习 django 并试图通过学习课程来制作一个 smartnotes 应用程序项目。 I updated the setting.py file to add website into Instaled_Apps.
我更新了 setting.py 文件以将网站添加到 Instaled_Apps。 Then have written a function named home in views.py Finally I added it's entry into urls.py fie "welcome.html is insdie homeApp/templates/home directory" But when I run the server, I am getting following error on webpage:
然后在views.py中写了一个名为home的function最后我将它添加到urls.py中fie“welcome.html是insdie homeApp/templates/home目录”但是当我运行服务器时,我在网页上收到以下错误:
views.py视图.py
from django.shortcuts import render
from django.http import HttpResponse
from django.http import HttpRequest
# Create your views here.
def home(request):
return render(request, 'home/welcome.html', {})
settings.py设置.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# apps that I created
'home',
]
urls.py网址.py
from django.contrib import admin
from django.urls import path
from django.urls import path
from home import views
urlpatterns = [
path('admin/', admin.site.urls),
path('home', views.home),
]
welcome.html欢迎。html
<title>
welcome Page
</title> </head> <body>
<h1>Hello world !!!</h1>
<h2>this is my first ever django project....</h2> </body> </html> ```
> **error its show is**
>
> Page not found (404) Request Method: GET Request URL:
> http://127.0.0.1:8000/
>
> Using the URLconf defined in smartappProject.urls, Django tried these
> URL patterns, in this order:
>
> admin/
> home
>
> The empty path didn’t match any of these.
Look at your urlpatterns
:看看你的
urlpatterns
:
urlpatterns = [
path('admin/', admin.site.urls),
path('home', views.home),
]
You haven't set the path for real "home" page, which should be ""
.您还没有设置真正的“主页”页面的路径,应该是
""
。 Change it to:将其更改为:
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),
]
And you will be fine.你会没事的。 The first argument in parenthesis is real "value" that you need to provide just after the domain (
http://localhost:8000/
with local service).括号中的第一个参数是您需要在域之后提供的真实“值”(
http://localhost:8000/
与本地服务)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.