python django - 找不到页面错误(404) - 静态错误

时间:2014-05-30 20:57:07

标签: python django django-models django-templates python-3.3

我以某种方式让应用程序在django上运行(对python和django来说是新的)虽然页面加载了默认URL(127.0.0.1:8000),但它确实加载了css文件。它产生以下错误,直接访问css文件。

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.

这是我的settings.py页面:

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")

    )

以下是urls.py页面:

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)

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

将任何类型的静态文件添加到项目后,您应该执行

python manage.py collectstatic