对于下面的目录结构,pycharm似乎无法检测从一个文件到另一个文件的导入
puzzle_project
__init__.py
snippets
__init__.py
models.py
views.py
对于models.py,代码为:
from django.db import models
from pygments.lexers import get_all_lexers
from pygments.styles import get_all_styles
LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted((item, item) for item in get_all_styles())
class Snippet (models.Model):
created = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=100, blank=True, default='')
code = models.TextField()
linenos = models.BooleanField(default=False)
language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)
class Meta:
ordering = ('created',)
对于views.py,代码为:
from snippets.models import Snippet
from snippets.serializers import SnippetSerializer
views.py将运行,但pycharm将这些行标记为Unresolved Refrence。只有当我重写这样的行:
from puzzle_project.snippets.models import Snippet
from puzzle_project.snippets.serializers import SnippetSerializer
将pycharm声明未解析的引用。请注意,上面的代码不会在python中运行。
请注意我使用的是最新版本的pycharm和python 3.4
如何让pycharm正确检查这些代码行?