[英]Django Admin Page not found (404), urls.py + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Going to http://127.0.0.1:8000/admin
returns this error:转到
http://127.0.0.1:8000/admin
返回此错误:
Using the URLconf defined in the_food_blog.urls, Django tried these URL patterns, in this order:
admin/
[name='home']
<slug:slug>/ [name='post_detail']
^(?P<path>.*)$
The current path, admin, matched the last one.
urls.py网址.py
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urls.py网址.py
urlpatterns = [
path('', views.PostList.as_view(), name='home'),
path('<slug:slug>/', views.PostDetail.as_view(), name='post_detail'),
]
Removing + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
fixes this but why?删除
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
解决了这个问题,但为什么呢?
You can use these:你可以使用这些:
urls.py网址.py
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
settings.py设置.py
MEDIA_URL = '/media/'
I hope to solve your problem!我希望能解决你的问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.