[英]Django 1.6.2 will not serve static content
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消息,在开发服务器中得到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: 主要urls.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. 我也曾在urls.py文件中尝试过django.conf.urls.static方法,但最终还是遇到了同样的问题。
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 "....." %}. URLS还可以使用{%static“ .....”%}在我的模板中很好地解析。
Relevant threads i have looked into (but haven't helped): 我研究过的相关线程(但没有帮助):
Django development server doesn't know nor care about STATIC_ROOT
or collected files. Django开发服务器既不了解也不关心
STATIC_ROOT
或收集的文件。 In order to correctly serve static files in development mode (aka using the runserver
command) you should place your static files in: 为了在开发模式下正确提供静态文件(也使用
runserver
命令),您应该将静态文件放在以下位置:
A directory called static
inside an app. 应用内的称为
static
的目录。
Any other directory listed in STATICFILES_DIRS
. STATICFILES_DIRS
列出的任何其他目录。
Additionaly you should set DEBUG
to True. 另外,您应该将
DEBUG
设置为True。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.