PyCharm can't find the right paths if I open a

2019-01-21 07:28发布

Our projects are usually structured:

/project-name
  /src
    /django-project-name
      etc..
readme.md
requirements.txt

If I open /project-name instead of /django-project-name PyCharm underlines my imports saying they can't find and it tries to reference imports as src.django-project-name.app_name.models.Thing which can't actually be found when you run Django.

How can I get it to work the same as when I mount /djang-project-name where it gets these things right?

3条回答
Deceive 欺骗
2楼-- · 2019-01-21 08:09

I had an issue with PyCharm not finding the templates folder for an existing Django project. So I created a test project and saw that the template folder setting is only added when setting up the project (it should be in project-root/.idea/project-name.iml)

Copying the same setting and changing the folder to the correct one fixed the issue for me.

查看更多
Fickle 薄情
3楼-- · 2019-01-21 08:18

I fixed it by going to File -> Preferences -> Project Structure selecting the /django-project-name in the tree and clicking sources to add it.

查看更多
小情绪 Triste *
4楼-- · 2019-01-21 08:27

Python requires an __init__.py file in each directory that is a module or part of the project, in pycharm you can add extra paths via preferences

查看更多
登录 后发表回答