Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get PyCharm to recognize the static files?

Tags:

python

pycharm

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?

like image 883
Kit Sunde Avatar asked Feb 22 '13 12:02

Kit Sunde


1 Answers

You need to set the following settings, to tell PyCharm where to find the project root:

enter image description here

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.

like image 64
Joris de Ruiter Avatar answered Oct 10 '22 05:10

Joris de Ruiter