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

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

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

  1. from django.urls import path
  2. from . import views
  3. urlpatterns = [
  4. path('notes/', views.notes_initiator, name='notes'),
  5. ]

Notes\views.py

  1. from django.shortcuts import render
  2. from django.http import HttpResponse
  3. def notes_initiator(request):
  4. return HttpResponse("Hello, world. You're at the notes index.")

Project\urls.py

  1. from django.contrib import admin
  2. from django.urls import include, path
  3. urlpatterns = [
  4. path('notes/', include('Notes.urls')),
  5. path('admin/', admin.site.urls),
  6. ]

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

  1. from django.urls import path
  2. from . import views
  3. urlpatterns = [
  4. path('notes/', views.notes_initiator, name='notes'),
  5. ]

Notes\views.py

  1. from django.shortcuts import render
  2. from django.http import HttpResponse
  3. def notes_initiator(request):
  4. return HttpResponse("Hello, world. You're at the notes index.")

Project\urls.py

  1. from django.contrib import admin
  2. from django.urls import include, path
  3. urlpatterns = [
  4. path('notes/', include('Notes.urls')),
  5. path('admin/', admin.site.urls),
  6. ]

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 中的代码。

  1. from django.contrib import admin
  2. from django.urls import include, path
  3. urlpatterns = [
  4. path('', include('Notes.urls')),
  5. path('admin/', admin.site.urls),
  6. ]
英文:

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

  1. from django.contrib import admin
  2. from django.urls import include, path
  3. urlpatterns = [
  4. path('', include('Notes.urls')),
  5. path('admin/', admin.site.urls),
  6. ]

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:

确定