我有一个类似如下的Django项目:
/.idea
/clients
/app
/static
coin.png
/templates
index.html
__init__.py
urls.py
/clients
settings.py
manage.py
在index.html中,我有以下代码(可以在渲染时看到图像):
{% load staticfiles %}
<img src="{% static 'coin.png' %}">
settings.py 相关部分:
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static/')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__), '../static/'),
)
INSTALLED_APPS = (
'django.contrib.staticfiles',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.static',
)
在项目结构中,我已经添加了/clients
,因为Django项目的根目录比仓库的根目录高一级。然而,在这个项目中,所有我的{% static %}
使用都被突出显示为不存在,尽管Django可以找到它们。有什么解决方法吗?
STATIC_ROOT = normpath(join(SITE_ROOT, 'assets'))
也遇到了同样的问题。PyCharm是否有一些手动设置静态目录的技巧?PyCharm EAP 129.782,django 1.5.1。 - b1_