Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved reference: 'django' error in PyCharm

I'm trying to import:

from django.db import models 

PyCharm underlines django.db and complains: Unresolved reference 'django'.

How do I get PyCharm to recognize Django?

like image 299
m4jesticsun Avatar asked Feb 09 '17 19:02

m4jesticsun


People also ask

How do I enable Django in PyCharm?

To enable Django support, follow these steps: Open the project Settings/Preferences dialog ( Ctrl+Alt+S ) and navigate to the Languages & Frameworks | Django page. Make sure that the checkbox Enable Django support is selected. Apply changes (if any) and close the dialog.

Can we use Django in PyCharm?

Sure, it is quite possible to run the Django server, then go to your browser, and type the entire URL in the address bar, but with PyCharm there is an easier way: use the pre-configured Django server run configuration with some slight modifications.


2 Answers

I assume you're using a virtualenv which is located in the same directory as other project files. Python should know exactly that path. So, it's possibly that Pycharm is using the wrong Interpreter.

Go to Settings -> Project: -> Project Interpreter -> switch to the right path

In the interpreter packages, there should be Django package installed. If not, do it here/in terminal.

like image 63
Elisabeth Shevtsova Avatar answered Oct 05 '22 23:10

Elisabeth Shevtsova


Mark root folder of project as 'Sources root', it works for me. Content Root

like image 43
Igor Z Avatar answered Oct 06 '22 01:10

Igor Z