How to set up a Django project in PyCharm

88,417

Solution 1

You can simply go to:

In Run -> Edit Configurations create new configuration
Script: path_to/manage.py
Script parameters: runserver

Solution 2

If you look at the features edition comparison matrix, you will see that only PyCharm Professional supports the Django Framework.

You can set up a project from the command line using the manage.py script and just open it in PyCharm. Then use the terminal to sync, start server etc...

You can use Eclipse PyDev with https://pydev.org/manual_adv_django.html. I have not tried it so I cannot say how good or bad it is.

There is a tutorial on setting up a new project here.

Wingware also seems to have some Django support.

Solution 3

I have met the problems today. At last, I finished it by:

  1. Create project in command line
  2. Create app in command line
  3. Just open the existing files and code in pycharm

The way I use have the benefits:

  • don't need by professional pycharm
  • code django project in pycharm

Solution 4

Pycharm integration with Django. Please try below steps for integration.

1. Add Django plugin inside your python interpreter

enter image description here

Click + icon for installation of Django

enter image description here Click on the install package, it will take some time for installation.

2. Check Django installation:

create a sample.py file

  import django
  print(django.get_version()) 

3. Open the terminal and entered

django-admin startproject mysite(name of your project)

4. Run Server

cd mysite
python manage.py runserver

You are able to start Django server at http://127.0.0.1:8000/

5. Create the application

Open the another terminal and entered

 cd mysite
 python manage.py startapp webapp(name of your app)

Please refer for more detail: https://www.youtube.com/watch?v=RUeLWSrtcFc

Solution 5

Note: I use pipenv to install dependencies, so I will assume you have it installed. Otherwise, follow these instructions. I use Python 3, so I will also use Django 2.

Using PyCharm 2019.1, 2018.3.1

I can state that it has become pretty simple the way to start a Django project.

  1. Open PyCharm, and select Create New Project.

enter image description here

  1. Choose Django in the left menu, provide a path and a name for your project. I strongly recommend using pipenv to manage your packages. Click on Create.

enter image description here

That's it. Wait to PyCharm to create a virtual environment, install Django, and and index files. Now you are all set. Click on the play button in upper run corner and you will see the Django launch page you can see at the end of this answer.

!######################################################!

Previous versions of PyCharm

First, let's create a project that will have the name of our Django project. I will call this directory mysite, and I will navigate inside of it.

$ mkdir mysite && cd mysite

Second, let's create a virtual environment using pipenv:

$ pipenv --three

Third, open up PyCharm, and click on Open. Browse to mysite directory, and click on Open.

enter image description here enter image description here

PyCharm will automatically recognize the virtual environment that you previously created, so if you open a terminal inside PyCharm, you will see the interpreter is actually set.

enter image description here

Fourth, from the terminal, install Django using pipenv and create a new project called mysite

$ pipenv install django
$ django-admin startproject mysite .

After running this commands your project directory should look like this:

enter image description here

mysite # this is the root project
├── Pipfile
├── Pipfile.lock
├── manage.py # this is the Manage script
└── mysite
    ├── __init__.py
    ├── settings.py # these are the settings
    ├── urls.py
    └── wsgi.py

Fifth, enable the Django support in Preferences -> Languages & Frameworks -> Django.

enter image description here

Check Enable Django Support, and provide the Django project root, Settings, and Manage script. Click on Apply and then OK.

enter image description here

Finally, you have to configure a Django server. Click on Add Configuration ... in the upper right.

enter image description here

Click on the plus sign in the upper left part, and select Django Server.

enter image description here

Provide a name, check Run browser if you want to open a tab when you click on the play button, and click on Apply and then OK.

enter image description here

Now you just can click on the play button in the right upper section.

enter image description here

Congrats! You are all set if you visualize the following page.

enter image description here

Share:
88,417
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm new in this area so I have a question. Recently, I started working with Python and Django. I installed PyCharm Community edition as my IDE, but I'm unable to create a Django project.

    I looked for some tutorials, and there is an option to select "project type", but in the latest version this option is missing. Can someone tell me how to do this?

  • Admin
    Admin about 10 years
    So much from free IDE. Can you suggest alternative free IDE for Python/Django?
  • Padraic Cunningham
    Padraic Cunningham about 10 years
    @user3676356, I added to my answer.
  • Deepend
    Deepend about 10 years
    +1 for Eclipse with PyDev, It can be a bit of a chore at the start but i love it now. PyDev has Django support as well. Youtube videos how setting up Django projects in Pydev are a very quick way to learn it.
  • Dale E. Moore
    Dale E. Moore almost 10 years
    What happens when Community pyCharm users open Professional pyCharm projects with Django extensions?
  • Bobort
    Bobort over 9 years
    @DaleE.Moore, it would just open it as regular Python files. The only issue is that Django is not integrated into the IDE, so you'd have to run the Django commands externally, such as runserver.
  • lmiguelvargasf
    lmiguelvargasf almost 5 years
    @AylianCraspa, this question has a tag PyCharm, and I am giving an answer for a version of PyCharm that I am using. I do not use the community edition, and I feel it is kind of disrespectful from your side to downvote my question just because I don't give an answer for your version.
  • Aylian Craspa
    Aylian Craspa almost 5 years
    you surly have but it is not accurate for the question title, we search this online to see how to setup pycharm community edition coz there is lot of posts available on the internet to work with pycharm professional edition.
  • JDOaktown
    JDOaktown over 4 years
    FelisCatus, is this answer still valid for Pycharm Community 2019?