python django - page not found error (404)- static error

这一生的挚爱 提交于 2020-01-06 03:11:47

问题


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?


回答1:


After you add any kind of static files to your project you should execute

python manage.py collectstatic



来源:https://stackoverflow.com/questions/23963325/python-django-page-not-found-error-404-static-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!