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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With