Django 1.6.2将不会提供静态内容 [英] Django 1.6.2 will not serve static content

查看:123
本文介绍了Django 1.6.2将不会提供静态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 Django == 1.6.2



无法提供静态内容 > 没有错误消息可以使用这个。



我刚刚在我的浏览器上添加了404消息,并发出了404消息开发者服务器

  [14 / Apr / 2014 16:50:29]GET / static / resource / css / bootstrap。 min.css HTTP / 1.1404 1697 

这是我的设置:

  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',



#以下所有目录已被检查并存在于磁盘上。
STATIC_URL ='/ static /'
MEDIA_URL ='/ media /'
STATIC_ROOT = os.path.join(SITE_ROOT,'site_media / static')
MEDIA_ROOT = path.join(SITE_ROOT,'site_media / media')

主要urls.py文件的内容: / p>

从$ d code从django.conf导入设置
从django.conf.urls导入模式,包括,url
从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')



如果settings.DEBUG:
urlpatterns + = staticfiles_urlpatterns()

调试模式在settings.py



我也在我的urls.py文件中尝试了django.conf.urls.static方法,但是我最终有同样的问题。



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



我能够在没有问题的情况下运行收藏。



URLS也可以使用{%static.....%}在我的模板中很好地解决。



相关线程我已经研究了(但没有帮助):



无法让Django提供静态文件



Django 1.6.2上的STATICFILES

解决方案

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


  1. 应用程序内的名为 static 的目录。


  2. p> STATICFILES_DIRS 中列出的任何其他目录。


您应该将 DEBUG 设置为True。


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.

这篇关于Django 1.6.2将不会提供静态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆