Django 无法访问指定的 URL,抛出 Not found 404。

huangapple go评论74阅读模式
英文:

Django can not access the url specified throwing Not found 404

问题

I'm getting Not Found: 404 error when trying to access http://127.0.0.1:8000/notes/ or http://127.0.0.1:8000/notes. My server is running and I can access the http://127.0.0.1:8000/admin but not the notes page. The app is registered in INSTALLED_APPS as well as its named Notes. I'm using Python 3.9 and Django 4.2.2

Notes\urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('notes/', views.notes_initiator, name='notes'),
]

Notes\views.py

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

def notes_initiator(request):
    return HttpResponse("Hello, world. You're at the notes index.")

Project\urls.py

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

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

I looked at similar problems with Django Not Found errors but they don't have a solution that would work for me.

I want to see the message "Hello, world. You're at the notes index." when accessing http://127.0.0.1:8000/notes/

英文:

I'm getting Not Found: 404 error when trying to access http://127.0.0.1:8000/notes/ or http://127.0.0.1:8000/notes. My server is running and I can access the http://127.0.0.1:8000/admin but not the notes page. The app is registered in INSTALLED_APPS as well as its named Notes. Im using Python 3.9 and Django 4.2.2

Notes\urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('notes/', views.notes_initiator, name='notes'),
]

Notes\views.py

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


def notes_initiator(request):
    return HttpResponse("Hello, world. You're at the notes index.")

Project\urls.py


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

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

I looked at similar problems with Django Not Found errors but they don't have solution that would work for me.

I want to see the message "Hello, world. You're at the notes index." when accessing http://127.0.0.1:8000/notes/

答案1

得分: 0

你能检查一下http://127.0.0.1:8000/notes/notes吗?
URL模式看起来不正确。

英文:

Hi can you check at http://127.0.0.1:8000/notes/notes.
The url pattern looks incorrect

答案2

得分: 0

要查看位于 http://127.0.0.1:8000/notes/ 的消息,请更新 Project\urls.py 中的代码。

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

urlpatterns = [
    path('', include('Notes.urls')),
    path('admin/', admin.site.urls),
]
英文:

To see the message at http://127.0.0.1:8000/notes/. Update the code in Project\urls.py

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

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

huangapple
  • 本文由 发表于 2023年7月28日 04:36:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76783252.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定