python django - 页面未找到错误(404) - 静态错误 [英] python django - page not found error (404)- static error
本文介绍了python django - 页面未找到错误(404) - 静态错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
找不到页面(404)
请求方法:GET
请求URL:http://127.0.0.1:8000/static/css/bootstrap.min.css
'css\bootstrap.min.css'找不到
你看到这个错误是因为您的Django设置文件中有DEBUG = True。将其更改为False,Django将显示标准的404页面。
这是我的settings.py页面:
STATIC_URL ='/ static /'
#模板位置
TEMPLATE_DIRS = {
os.path.join(os.path。 dirname(BASE_DIR),whattheheck,static,templates),
}
如果DEBUG:
MEDIA_URL ='/ media /'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR),whattheheck,static,static-only)
MEDIA_ROOT = os.path.join(os.path。 dirname(BASE_DIR),whattheheck,static,media)
STATICFLIES_DIRS =(
os.path.join(os.path.dirname(BASE_DIR),whattheheck,static ,static)
)
而这是urls.py页面:
from django.conf.urls import patterns,include,url
from django.conf导入设置
从django.conf.urls.static import static
from django.contrib import admin
admin.autodiscover()
urlpatter ns = patterns('',
#示例:
url(r'^ $','signups.views.home',name ='home'),
#url(r' ^ blog /',include('blog.urls')),
url(r'^ admin /',include(admin.site.urls)),
)
如果settings.DEBUG:
urlpatterns + = static(settings.STATIC_URL,
document_root = settings.STATIC_ROOT)
urlpatterns + = static设置.MEDIA_URL,
document_root = settings.MEDIA_ROOT)
有人可以帮忙吗?
解决方案
在您的项目中添加任何类型的静态文件后,您应该执行
python manage.py collectstatic
I somehow got the application running on django (new to python and django) and although the page loads the default URL (127.0.0.1:8000) but it does load the css files. It produces following error css files are directly accessed.
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/static/css/bootstrap.min.css
'css\bootstrap.min.css' could not be found
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Here is my settings.py page:
STATIC_URL = '/static/'
# Template location
TEMPLATE_DIRS = {
os.path.join(os.path.dirname(BASE_DIR), "whattheheck", "static", "templates"),
}
if DEBUG:
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "whattheheck", "static", "static-only")
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "whattheheck", "static", "media")
STATICFLIES_DIRS = (
os.path.join(os.path.dirname(BASE_DIR), "whattheheck", "static", "static")
)
and Here is the urls.py page:
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'signups.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
can someone help with this please?
解决方案
After you add any kind of static files to your project you should execute
python manage.py collectstatic
这篇关于python django - 页面未找到错误(404) - 静态错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文