Django - 应用程序目录中的静态文件 [英] Django - Static Files from App Directories

查看:127
本文介绍了Django - 应用程序目录中的静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发环境中,我想使用应用程序目录中的静态文件。

In a development environment, I'd like to use static files from the app directories.

#settings.py

SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
STATIC_ROOT = (os.path.join(SITE_ROOT, 'static_files/'))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
  os.path.join(SITE_ROOT, 'static/'),
)
STATICFILES_FINDERS = (
  'django.contrib.staticfiles.finders.FileSystemFinder',
  'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
TEMPLATE_CONTEXT_PROCESSORS = (
#...
  'django.core.context_processors.static',
#...
)
INSTALLED_APPS = (
#...
  'django.contrib.staticfiles',
#...
)

我可以找到我的静态文件,如果位于 /static/css/file.css ,但如果在 an_app / static / css / file.css p>

I can find my static file if located in /static/css/file.css but not if in an_app/static/css/file.css.

推荐答案

确定我发现问题,我疯了在我的问题上是一个不可见的监督。我正在搜索 static / js static / flash static / css static / images 并将文件直接放入app / static中,以便找不到。

Ok I found the problem, I made an oversight that was not visible in my question. I was searching into in static/js, static/flash, static/css, static/images and put the files directly into app/static so they were not found.

这篇关于Django - 应用程序目录中的静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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