1

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?

5
  • Where is css/bootstrap.min.css in your file system? Commented May 30, 2014 at 21:30
  • miss coma in STATICFLIES_DIRS = (os.path.join(os.path.dirname(BASE_DIR), "whattheheck", "static", "static"), <-- here ) f you really don`t have it - try to add Commented May 30, 2014 at 22:33
  • @HuuNguyen It is in the following location. C:\Python33\Scripts\whattheheck\static\static\css Commented May 31, 2014 at 19:01
  • @zymud that didn't work:( Commented May 31, 2014 at 19:03
  • @HuuNguyen even if I try to change the url http://127.0.0.1:8000/static/css/bootstrap.min.css to http://127.0.0.1:8000/whattheheck/static/static/css/bootstrap.min.css http://127.0.0.1:8000/static/static/css/bootstrap.min.css It still doesn't open :( Commented May 31, 2014 at 19:13

1 Answer 1

0

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

python manage.py collectstatic

Sign up to request clarification or add additional context in comments.

4 Comments

Okay, I changed the way i express myself
@Liarez I have done that already, I guess that is why I am able to open the page on the browser but for some reason css is not loading.
Your STATIC_ROOT is getting the path to the static files good ? You can try to change your actual STATIC_ROOT for something like STATIC_ROOT=/var/www/path/to/static
Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/whattheheck/static/static/css/bootstrap.min.css Using the URLconf defined in whattheheck.urls, Django tried these URL patterns, in this order: ^$ [name='home'] ^admin/ ^static\/(?P<path>.*)$ ^media\/(?P<path>.*)$ The current URL, whattheheck/static/static/css/bootstrap.min.css, didn't match any of these. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.