Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error running Django in Intellij / Pycharm

i have problem running Django server in Intellij / Pycharm (I tried in both).

There is that red cross:

enter image description here

And this is the error i get:

Error running Django: Please select Django module

I have Python 2.7.10 and Django (via pip) installed on my computer. I've tried reinstalling both python and Django, but it didn't help. I've specified project sdk (Python).

Edit:

This is what it looks like in "Project Interpreter" page.

enter image description here

and Django configuration:

enter image description here

like image 999
Broccoli Avatar asked Apr 15 '16 19:04

Broccoli


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 I use Django in IntelliJ?

IntelliJ IDEA supports the latest Django versions.

How does PyCharm detect Django?

If you cannot print the Django version from the python console in Pycharm, go to settings>Project:project_name>project Interpreter and from the list of installed packages see the installed Django and it's version for that project.

Is Django already installed in PyCharm?

Step 1: Open Your PyCharm and Click on Create New Project. Step 2: Select Your Directory and then give a name to your project and then Click on Create. Step 3 : Then Check if Django is installed or not in your Computer. If it is Already installed then you will see the Django version installed in Your Computer.


2 Answers

If your IntelliJ is up to date, there is another solution.

I had the exact same problem in IntelliJ 2017.2 and it was driving me crazy until I read this post from a IntelliJ maintainer.

If you use IntelliJ Idea and "Load an existing project", it will model it as a Java project with a Python modules attached. You cannot get Django loaded, no matter what you do.

I handled this by purging the .idea directory, and created a new Django project, with the pre-existing Django directory as the base directory in IntelliJ. I can now see Django in the project structure > project settings > module part of Intellij, and I can select the django settings file.

Step by step in pictures

  1. Delete .idea folder

  2. Create new project Create new project

  3. Select Python > Django Select Python > Django

  4. Hit next Hit next

  5. Select existing django project path (or start from scratch with a new folder) Enter existing project path

  6. Add DJANGO_SETTINGS_MODULE=yourprojectname.settings to your run configuration (can be found in yourprojectname/wsgi.py file).

Edit run configuration

Add env variable

Enjoy your Django development 🚀

like image 138
jbm Avatar answered Sep 17 '22 14:09

jbm


Try adding DJANGO_SETTINGS_MODULE=untitled.settings to the environment variables listed in the configuration menu by clicking the dropdown titled 'Django' in your first photo.

like image 41
Curtis Olson Avatar answered Sep 21 '22 14:09

Curtis Olson