简体   繁体   English

找不到页面 404 - Django

[英]Page not found 404 - Django

I'm a newbie to Django and I know this probably has been asked alot of times.我是 Django 的新手,我知道这可能已经被问过很多次了。

So basically what's happening is when I try to create a new project and whenever I'm trying to run my server, by default it's opening http://127.0.0.1:8000/catalog/ and not http://127.0.0.1:8000/ .所以基本上发生的事情是当我尝试创建一个新项目并且每当我尝试运行我的服务器时,默认情况下它打开http://127.0.0.1:8000/catalog/而不是http://127.0.0.1: 8000/

Even if I run the server with my other projects, I'm facing the same error.即使我与其他项目一起运行服务器,我也面临同样的错误。

I followed this django basics tutorial on https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/skeleton_website我在https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/skeleton_website上遵循了这个 django 基础教程

Idk but somehow I think it's default address is set to http://127.0.0.1:8000/catalog/ . Idk,但不知何故,我认为它的默认地址设置为http://127.0.0.1:8000/catalog/

Here's the link to the repo for the project: https://github.com/Fanceh/django-404-error这是该项目的存储库的链接: https://github.com/Fanceh/django-404-error

Here's my project's urls.py:这是我项目的 urls.py:

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

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

Here's the code in my testuapp urls.py:这是我的 testuapp urls.py 中的代码:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.testu),
]

Here's my webapp's views.py file:这是我的 webapp 的 views.py 文件:

from django.shortcuts import render

# Create your views here.

def testu(request):
    render(request, 'Greetings!')

Is there any way I can change it?有什么办法可以改变它吗?

Regards问候

From the tutorial link it mentions the redirect.从教程链接中,它提到了重定向。 Any request for the root URL, will redirect you to /catalog.对根 URL 的任何请求都会将您重定向到 /catalog。

Screenshot from the tutorial below.以下教程的屏幕截图。

HTH HTH

从教程重定向

so i assume you are below url pattern structure in your testuapp project.所以我假设你在你的 testuapp 项目中低于 url 模式结构。

urlpatterns = [
        path('catalog',include("views.catalog"))
]

views.calalog is the name of the method in your view file. views.calalog 是视图文件中方法的名称。

Ok I think I figured it out, it's just the chrome cache.好的,我想我明白了,这只是 chrome 缓存。 I cleared it and bam it's working!我清除了它并且它正在工作!

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

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