Eclipse / PyDev / Django import requires project name

Develop a project in Django with installing an IDE as Eclipse with PyDev. The following import statement:

from polls.models import Poll, Choice 

works when starting a project from the command line with:

 python manage.py runserver 

However, built-in error checking with Eclipse does not find polls.models ("unauthorized import port"). I can fix this by adding a project name in front of the class and then running it. That is, do the import statement:

 from projectName.polls.models import Poll, Choice 

The problem is that I am collaborating with the project and cannot do this.

Question: Is there a way to automatically detect Eclipse or guess the project name from the import statement?

+4
source share
1 answer

Using projectName in import statements is not a good idea.

When working with django / python, start using virtualenv. Especially when working with eclipse / pydev. You can configure a new interpreter for each virtualenv. Just add virtualenv to the list of interpreters in the section "Settings> PyDev> Interpreter - Python" and remember to add your djangoproject root directory to PYTHONPATH on the same settings page.

This, in essence, is what django does for you when you start from the command line.

+3
source

Source: https://habr.com/ru/post/1390118/


All Articles