繁体   English   中英

使用在 Lecture3.urls 中定义的 URLconf,Django 尝试了这些 URL 模式,顺序如下: admin/ 当前路径,hello/,不匹配任何一个

[英]Using the URLconf defined in lecture3.urls, Django tried these URL patterns, in this order: admin/ The current path, hello/, didn’t match any of thes

我不熟悉使用 Django 并遵循教程( https://video.cs50.io/w8q0C-C1js4?screen=gytX_rSwZRQ&start=1160 )。

到目前为止,这门课程很棒,但是。 现在我坚持使用 Django 成功创建一个新应用程序。

这是我努力的结果:[ Lecture3 Page not found

结果应该是这样的: Hello, World page when found tutorial

据我所知,我所做的一切都是正确的,也许我错过了什么?

下面是我正在使用的代码,它导致 Django 返回标题中的错误:

urls.py 讲座 3:

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

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

urls.py 你好:

    from django.urls import path

    from . import views

    urlpatterns = [
    path("", views.index, name="index")
    ]

视图.py:

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

    # Create your views here.
    def index(request):
    return HttpResponse("Hello, World!")

设置.py:

    INSTALLED_APPS = [
    'hello',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ]

我目前正在使用:Python 3.9.4 和 Django 3.2.3

任何和所有可以提供的帮助将不胜感激。

在此先感谢,理查森

问题来自“attempttwo.urls”,因此请修改您的设置文件。

您提供的路径是 path('hello/', include("hello.urls")) 当您运行 python3 manage.py runserver 时,您需要在浏览器中 url 的末尾添加“/hello”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM