使用简单路径找不到 Django 页面
Django Page not found using simple path
我使用的是 django 版本 2.1.4。
在我的项目中创建了应用程序 'main' 并尝试进入其 urls.py 以在 admin/main/test/
下显示句子 "text"
但是当 admin/ 和 admin/main/ 工作时,admin/main/test/ 给出错误
Page not found (404) Request Method: GET Request URL:
http://127.0.0.1:8000/admin/main/test
Using the URLconf defined in statystyki.urls, Django tried these URL
patterns, in this order:
main/
admin/ [name='index']
admin/ login/ [name='login']
admin/ logout/ [name='logout']
admin/ password_change/ [name='password_change']
admin/ password_change/done/ [name='password_change_done']
admin/ jsi18n/ [name='jsi18n']
admin/ r/<int:content_type_id>/<path:object_id>/ [name='view_on_site']
admin/ auth/group/
admin/ auth/user/
admin/ main/movie/
admin/ ^(?P<app_label>auth|main)/$ [name='app_list']
The current path, admin/main/test, didn't match any of these.
我的文件:
statystyki/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('main/', include('main.urls')),
path('admin/', admin.site.urls),
]
main/urls.py
from django.urls import path
from .views import test_response
urlpatterns = [
path('test/', test_response),
]
views.py
from django.shortcuts import render
from django.http import HttpResponse
def test_response(request):
return HttpResponse('test')
你能帮我找出导致这个问题的原因吗?我已经将 'main' 添加到 settings.py
中已安装的应用程序
您正在尝试访问错误的 url。尝试从 url 中删除 /admin
。
因此 url 将是 http://127.0.0.1:8000/main/test/
admin/', admin.site.urls
管理路径仅适用于默认应用程序,因此当您尝试从中检索您的主应用程序页面时,会显示您反击的错误。您应该尝试使用包含路径 path('main/', include('main.urls')),
的 URL ,然后跟随主路径的内部路径 path('test/', test_response),
简而言之,您应该:
http://localhost:8000/main/test/
我使用的是 django 版本 2.1.4。
在我的项目中创建了应用程序 'main' 并尝试进入其 urls.py 以在 admin/main/test/
下显示句子 "text"但是当 admin/ 和 admin/main/ 工作时,admin/main/test/ 给出错误
Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/admin/main/test
Using the URLconf defined in statystyki.urls, Django tried these URL patterns, in this order:
main/ admin/ [name='index'] admin/ login/ [name='login'] admin/ logout/ [name='logout'] admin/ password_change/ [name='password_change'] admin/ password_change/done/ [name='password_change_done'] admin/ jsi18n/ [name='jsi18n'] admin/ r/<int:content_type_id>/<path:object_id>/ [name='view_on_site'] admin/ auth/group/ admin/ auth/user/ admin/ main/movie/ admin/ ^(?P<app_label>auth|main)/$ [name='app_list']
The current path, admin/main/test, didn't match any of these.
我的文件:
statystyki/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('main/', include('main.urls')),
path('admin/', admin.site.urls),
]
main/urls.py
from django.urls import path
from .views import test_response
urlpatterns = [
path('test/', test_response),
]
views.py
from django.shortcuts import render
from django.http import HttpResponse
def test_response(request):
return HttpResponse('test')
你能帮我找出导致这个问题的原因吗?我已经将 'main' 添加到 settings.py
中已安装的应用程序您正在尝试访问错误的 url。尝试从 url 中删除 /admin
。
因此 url 将是 http://127.0.0.1:8000/main/test/
admin/', admin.site.urls
管理路径仅适用于默认应用程序,因此当您尝试从中检索您的主应用程序页面时,会显示您反击的错误。您应该尝试使用包含路径 path('main/', include('main.urls')),
的 URL ,然后跟随主路径的内部路径 path('test/', test_response),
简而言之,您应该:
http://localhost:8000/main/test/