PyCharm - Unresolved library 'staticfiles'

北慕城南 提交于 2019-12-03 10:45:33

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.

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.

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.

Using PyCharm 2019.2, once the settings.py is correctly pointed to in django preferences config panel I needed to invalidate the cache and restart before Pycharm correctly recognised all templatetags library, even if my INSTALLED_APPS is dynamically built.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!