PyCharm-未解析的库“ staticfiles” [英] PyCharm - Unresolved library 'staticfiles'

查看:368
本文介绍了PyCharm-未解析的库“ staticfiles”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PyCharm进行Django项目。不幸的是,PyCharm无法解析我想在模板中使用的模板标签。

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 %}

该项目通过vagrant在Ubuntu VM中运行。运行配置知道我正在VM中使用的virtualenv(远程解释器设置)。

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).

我的设置如下:

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'),
)

仍然收到警告未解析的库'staticfiles'。它也显示与其他模板标签相同的行为。
是动态创建 STATICFILES_DIRS 的问题吗?我怎么解决呢?

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?

推荐答案

事实证明,动态创建 INSTALLED_APPS 以某种方式混淆了PyCharm。如果这些依赖项是动态创建的,则无法解析某些依赖项,例如 template_tags 。似乎必须决定要使用一个不错的代码导航还是静态的 INSTALLED_APPS

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.

这篇关于PyCharm-未解析的库“ staticfiles”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆