简体   繁体   中英

Page not found 404 - Django

I'm a newbie to Django and I know this probably has been asked alot of times.

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/ .

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

Idk but somehow I think it's default address is set to http://127.0.0.1:8000/catalog/ .

Here's the link to the repo for the project: https://github.com/Fanceh/django-404-error

Here's my project's 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:

from django.urls import path
from . import views

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

Here's my webapp's views.py file:

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.

Screenshot from the tutorial below.

HTH

从教程重定向

so i assume you are below url pattern structure in your testuapp project.

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

views.calalog is the name of the method in your view file.

Ok I think I figured it out, it's just the chrome cache. I cleared it and bam it's working!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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