简体   繁体   中英

Django 1.6.2 will not serve static content

I am unable to serve static content (for development purposes) using Django==1.6.2

There is no error message available to go with this.

I just end up with a 404 message on my browser and a 404 message in the dev server

[14/Apr/2014 16:50:29] "GET /static/resource/css/bootstrap.min.css HTTP/1.1" 404 1697

This is my set-up:

INSTALLED_APPS = (
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',

 # Django extra
 'django.contrib.webdesign',
)


# All directories below have been checked and exist on disk.
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(SITE_ROOT, 'site_media/static')
MEDIA_ROOT = os.path.join(SITE_ROOT, 'site_media/media')

Content of main urls.py file:

from django.conf import settings
from django.conf.urls import patterns, include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    # ADMIN
    url(r'^admin/', include(admin.site.urls)),

    # HOMEPAGE
    url(r'^$', 'mainmodule.views.home', name='home')

)

if settings.DEBUG:
    urlpatterns += staticfiles_urlpatterns()

Debug mode is turned on in settings.py

I have also tried the django.conf.urls.static method in my urls.py file but i end up with the same problem.

My static directory is not situated inside an app. I never had a problem with this and i cannot find any information regarding this on the official Django docs

I am able to run collectstatic with no problems.

URLS also resolve nicely inside my templates using {% static "....." %}.

Relevant threads i have looked into (but haven't helped):

Can't get Django to serve static files

STATICFILES on Django 1.6.2

Django development server doesn't know nor care about STATIC_ROOT or collected files. In order to correctly serve static files in development mode (aka using the runserver command) you should place your static files in:

  1. A directory called static inside an app.

  2. Any other directory listed in STATICFILES_DIRS .

Additionaly you should set DEBUG to True.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM