0

Setting up virtual environment

$ pip3 install virtualenv virtualenvwrapper
$ mkdir Django; cd Django;
$ virtualenv django-virtual-env -p python3
$ ls django-virtual-env 
bin        lib        pyvenv.cfg
$ source django-virtual-env/bin/activate
(django-virtual-env) $ 
(django-virtual-env) $ which python3
$PWD/env_blog/bin/python3
(django-virtual-env) $ deactivate
$

pip dependencies required

pip install django

Setting up intellij for your project

  • Configure Python interpreter

    • File -> Project Structure -> SDKs -> + -> Add Python SDK -> Virtual Environment -> Existing Environment -> (Set the interpretter to absolute path) ./django-virtual-env/bin/python
  • Configure the project to be able to import the python modules

Still the following syntax is not getting detected. The code is correct and working. Not sure what is the issue

enter image description here

enter image description here

codeaprendiz
  • 2,703
  • 1
  • 25
  • 49

1 Answers1

0

Django project configuration in IDEA is quite cumbersome, please vote for the corresponding ticket in PyCharm's bug tracker https://youtrack.jetbrains.com/issue/PY-34155 The ticket has a screencast demonstrating the setup.

I believe the easiest way is:

  • Lets assume we have a directory A which is a Django project root
  • Open A in IDEA
  • Open File | Project Structure
  • Open Project Settings | Modules
  • Remove the existing module if doesn't have Django facet under it right away
  • Click + and Import Module -> Select A
  • Create module from existing sources
  • Once done - select Django facet and populate it's settings
Pavel Karateev
  • 7,737
  • 3
  • 32
  • 59