开发者

Django - Static Files from App Directories

开发者 https://www.devze.com 2023-03-13 22:15 出处:网络
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__))

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',
#...
)

I can find my static file if located in /static/css/file.css but not if in an_app/static/css/file.c开发者_如何学Pythonss.


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.


Check the value of STATIC_ROOT and STATICFILES_DIRS. Add a print in your setting file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号