Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm - Unresolved library 'staticfiles'

I'm working on a Django project with PyCharm. Unfortunately PyCharm does not resolve the template tags I would like to use in my templates.

{% load staticfiles %}

The project is running within an Ubuntu VM via vagrant. The run configuration knows about the virtualenv I am using in the VM (remote interpreter setup).

My settings look like this:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.humanize',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.flatpages',
    'django_extensions']

INSTALLED_APPS += get_core_apps(['myapp.dashboard')

STATICFILES_FINDERS = (
    'compressor.finders.CompressorFinder',
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
)

STATIC_URL = '/static/'

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, '../../../../myfolder/static'),
)

Still I get the warning Unresolved library 'staticfiles'. It shows the same behavior other template tags as well. Could the dynamic creation of the STATICFILES_DIRS be the issue? How could I solve this?

like image 505
RodrigoDela Avatar asked Jan 08 '16 14:01

RodrigoDela


3 Answers

In my case this happened when PyCharm couldn't find settings.py file. This because I have - local_setting, prod_setting etc. So I go to File -> Settings -> Language & Framworks -> Django -> Settings and select appropriate file with setting of django project.

like image 141
Tim Avatar answered Sep 20 '22 14:09

Tim


It turned out that the dynamical creation of INSTALLED_APPS confuses PyCharm somehow. It cannot resolve certain dependencies such as the template_tags if these are created dynamically. Seems like one has to decide whether to have a nice code navigation or static INSTALLED_APPS.

like image 31
RodrigoDela Avatar answered Sep 18 '22 14:09

RodrigoDela


It looks like PyCharm looks for the last assignment to INSTALLED_APPS to find template tags. I have run into a similar problem and be able to work around it adding this after dynamically generating the real INSTALLED_APPS:

if False:
    INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        'django.contrib.staticfiles',
        'autocomplete_light',
        'django.contrib.admin',
        'django.contrib.humanize',
        'comunes',
        'listados',
        'gescomercial',
        'contabilidad',
        'compras',
        'almacen')

Not pretty, but as this settings.py is only used in the development machine I can live with it.

like image 23
Javier Rivera Avatar answered Sep 21 '22 14:09

Javier Rivera