Reputation: 37075
I have one Django project that looks like:
/.idea
/clients
/app
/static
coin.png
/templates
index.html
__init__.py
urls.py
/clients
settings.py
manage.py
In index.html I have (I can see the image on render):
{% load staticfiles %}
<img src="{% static 'coin.png' %}">
Relevant parts of 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',
)
In project structure I've added /clients
since the root of the Django project is one level up from the repo root. However all my {% static %}
uses in this project keep getting highlights as not existing even though Django can find them. Ideas on how to resolve this?
Upvotes: 8
Views: 7233
Reputation: 178
You need to set the following settings, to tell PyCharm where to find the project root:
Django settings to set (image)
You can also use {{STATIC_URL}}/path/to/files, which works different by pycharm
This worked wonders. It is a bit strange of pycharm though.
Upvotes: 12
Reputation: 82470
STATICFILES_DIRS = (
'static',
)
The above assumes that your static dir is called static
right under your root. Now need to do os.path.join
. I've tried and tested this.
Upvotes: 12