Django 1.6.2不提供静态内容

时间:2021-01-31 19:16:55

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

我不能使用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

最后,我的浏览器上有一个404消息,在dev服务器上有一个404消息。

[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:

主要内容的url。py文件:

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

在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.

我也尝试过django.conf.urls。我的url中的静态方法。py文件,但最后我还是遇到了同样的问题。

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

我的静态目录不在一个应用程序中。我从来没有遇到过这个问题,我在Django官方文档中找不到任何关于这个问题的信息

I am able to run collectstatic with no problems.

我能毫无问题地运行collectstatic。

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

url也很好地解决了我的模板内使用{%静态的“……”% }。

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

我研究过的相关线索(但没有帮助):

Can't get Django to serve static files

不能让Django提供静态文件

STATICFILES on Django 1.6.2

在Django STATICFILES 1.6.2

1 个解决方案

#1


1  

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:

Django开发服务器不知道也不关心STATIC_ROOT或收集的文件。为了在开发模式下正确地服务静态文件(即使用runserver命令),您应该将您的静态文件放在:

  1. A directory called static inside an app.

    一个被称为静态内部应用程序的目录。

  2. Any other directory listed in STATICFILES_DIRS.

    在STATICFILES_DIRS中列出的任何其他目录。

Additionaly you should set DEBUG to True.

此外,您应该将DEBUG设置为True。

#1


1  

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:

Django开发服务器不知道也不关心STATIC_ROOT或收集的文件。为了在开发模式下正确地服务静态文件(即使用runserver命令),您应该将您的静态文件放在:

  1. A directory called static inside an app.

    一个被称为静态内部应用程序的目录。

  2. Any other directory listed in STATICFILES_DIRS.

    在STATICFILES_DIRS中列出的任何其他目录。

Additionaly you should set DEBUG to True.

此外,您应该将DEBUG设置为True。