Create a Django project
Django project is intended for productive web development with Django. PyCharm takes care of creating specific directory structure and files required for a Django application, and providing the correct settings.
Create a new Django project
From the main menu, choose File | New Project , or click the New Project button in the Welcome screen. New Project dialog opens.
In the New Project dialog, do the following:
Specify project type Django .
Specify project location.
Next, choose whether you want to create a new environment or use an existing interpreter, by clicking the corresponding radio-button.
If this option has been selected, choose the tool to be used to create a virtual environment. To do that, click the list and choose Virtualenv , Pipenv , Poetry , or Conda .
Next, specify the Location and Base interpreter of the new virtual environment.
Select the Inherit global site-packages checkbox if you want all packages installed in the global Python on your machine to be added to the virtual environment you’re going to create. This checkbox corresponds to the —system-site-packages option of the virtualenv tool.
Select the Make available to all projects checkbox if you want to reuse this environment when creating Python interpreters in PyCharm.
If PyCharm detects no Python on your machine, it provides the following options:
Specify a path to the Python executable (in case of non-standard installation)
Download and install the latest Python versions from python.org
Install Python using the Command-Line Developer Tools (macOS only).

If this option has been selected, choose the desired interpreter from the list, or (if the desired interpreter is not found), click Add Interpreter and choose the interpreter.
When PyCharm stops supporting any of the outdated Python versions, the corresponding Python interpreter is marked as unsupported.
Click ( More Settings ), and specify the following:
From the Template language list, select the language to be used.
In the Templates folder field, specify the directory where the templates will be stored, and where they will be loaded from. You can specify the name of the directory that doesn’t yet exist; in this case, the directory will be created.
In the Application name field, type the name of the Django application to be created.
The name of a Django application should not be the same as the Django project name.
If you need admin interface to be created, select the Enable Django admin checkbox.
If Django is missing in the selected interpreter, PyCharm displays an information message that Django will be downloaded.
Step 4. Create and Run your first Django project
You are working with PyCharm version 2022.2 or later. If you still do not have PyCharm, download it from this page. To install PyCharm, follow the instructions, depending on your platform.
This tutorial has been created with the following assumptions:
The example used in this tutorial is similar to the one used in Django documentation.
Creating a new project
From the main menu, choose File | New Project , or click the New Project button in the Welcome screen. New Project dialog opens.
In the New Project dialog, do the following:
Specify project type Django .
If required, change the default project location.
Select New environment using Virtualenv
Click ( More Settings ), and specify polls in the Application name field.
Exploring project structure
The newly created project contains Django-specific files and directories.
The structure of the project is visible in the Project tool window:
MyDjangoProject directory is a container for your project. It is denoted with bold font.
manage.py is a command-line utility that lets you interact with your Django project. Refer to the Django documentation for details.
The nested directory MyDjangoProject is the actual Python package for your project.
MyDjangoProject/__init__.py : This empty file tells Python that this directory should be considered a Python package.
MyDjangoProject/settings.py : This file contains configuration for your Django project.
MyDjangoProject/urls.py : This file contains the URL declarations for your Django project.
MyDjangoProject/wsgi.py : This file defines an entry-point for WSGI-compatible web servers to serve your project. See How to deploy with WSGI for more details.
The nested directory polls contains all the files required for developing a Django application:
Again, polls/_init_.py tells Python that this directory should be considered a Python package.
polls/models.py : In this file, we’ll create models for our application.
polls/views.py : In this file, we’ll create views.
templates directory is by now empty. It will contain Django templates.
The nested directory migrations contains by now only the package file _init_.py , but will be used in the future to propagate the changes you make to your models (adding a field, deleting a model, and so on) into your database schema. Read the migrations description here.
Launching Django server
The Django server run/debug configuration is created automatically. If required, you can edit it by selecting the Edit Configurations command in the run/debug configuration list on the main toolbar:

For example, you can choose to open a browser window automatically when the configuration is launched:

Run the MyDjangoProject configuration by clicking . If a browser window does not open automatically, click the link in the Run tool window.

The following page opens:
Writing views
Django views are functions that take web request and return web responses. By convention, views are defined in views.py files inside of project and application directories.
Open the file polls/views.py and type the following Python code:
The above message will be shown on the index page of the polls application.
Now we need to instruct the application to render the index view.
In the polls directory, create the file urls.py and type the following code in it:
Next, open the file MyDjangoProject/urls.py (which PyCharm has already created for you) and add a URL for the index page. You should end up with the following code:
Don’t forget to import django.urls.include !
Open the page http://127.0.0.1:8000/polls/ in your browser. You should see the following text:
Next, let’s add more views. Add the following code to the file polls/views.py :
The above views take one argument ( question_id ), and then use it in the responses.
Map these new views to URLs by adding patterns in the /polls/urls.py file. The full code should look as follows:
If you now open the corresponding pages in your browser, you will see the following:

Creating database
By default, PyCharm automatically creates an SQLite database for a Django project.
We need to create the tables in the database for all applications in the current Django project. To do that, press Ctrl+Alt+R and type migrate followed by Enter in the manage.py console, that opens.
You should see Process finished with exit code 0 in the console output.
Creating and activating models
Django models define the fields and behaviors of your data. They are represented by Python classes, which are subclasses of the django.db.models.Model class.
Let’s create two models for our polls app: Question and Choice . To do that, open the file polls/models.py , and add the following code after the import statement:
Each model here has class variables represented by instances of a Field class:
The Question model:
question_text . An instance of the CharField class, contains the text of the question.
pub_date . An instance of the DateTimeField class, contains the publication date of the question.
‘date published’ is an optional first positional argument representing the human-readable name of the field.
The Choice model:
question . Association with a Question .
choice_text . An instance of the CharField class, contains the text of the choice.
votes . An instance of the IntegerField class, contains the vote tally.
For more information about model fields, refer to the Django documentation.
To make Django aware of the new models, run the following command in the manage.py console:
The polls/migrations directory now contains the migration file 0001_initial.py :

Migrations are human-editable files, in which Django stores changes to data models. To apply changes and create tables in the database for the two new models, run the migrate command again:

Performing administrative functions
Admin sites are used to add, edit, and otherwise manage the content. Django allows creating an admin site for your project automatically.
Setting up an admin site
Firstly, we need to create a superuser. To do that, type the createsuperuser command in the manage.py console, specify your email address, and password:
Now go to /admin/ on your Django server, for example, http://127.0.0.1:8000/admin/. You should see the following login page:
After you log in, the administration page is displayed. It has a section Authentication and Authorization (Groups and Users) , but Polls is not available. Why so?
We must tell the admin that Question objects have an admin interface.
Adding content
Open the file polls/admin.py , and type the following code:
Refresh the page in the browser. The Polls section with Questions should appear:
Click Add to create a question:

When you a ready, click SAVE .
The newly created question appears in the list as Question object (1) . Such naming makes content management complicated, as you have to open each question to see its text.
Let’s fix it by adding a __str__() method for both Question and Choice . Open polls/models.py and add the following lines:
You should end up with the following:

The list of questions now consists of human-readable names:
By design, each question must have a number of choices. However, choices are still not available in the admin interface. Let’s fix that.
Providing features
Open the file polls/admin.py and edit it to get the folowing result:
Now you can add choices to a question:
Creating Django templates
Until now, the design of the polls application pages has been hardcoded in views. To make the application usable, you need to separate the visual representation of the output from the Python code. That can be done by using Django templates.
Open the file polls/views.py and replace its contents with the following code:
You can see unresolved references to the template files index.html , detail.html , and results.html :

PyCharm suggests a quick-fix: if you click the light bulb, or press Alt+Enter , you can choose to create the corresponding template file in the templates folder:

PyCharm also creates the directory polls where this template should reside. Confirm this operation:

By now, the file index.html is empty. Fill it with the following code:
The code generates the list of available questions, or displays "No polls are available" if there are none.
Pay attention to the icons and
that appear in the gutter of the files views.py and index.html respectively:
These icons enable you to jump between a view method and its template straight away. Read more about this kind of navigation in the articles Navigate between templates and views and Part 6. Django-specific navigation.
Now let’s add the detail.html template file with the code that generates a page with a question text, radio buttons for choices, and a Vote button:
The results.html template will generate a page with voting results for all choices and a link for answering the same question again. Create the file and fill it with the following code:
Go to http://127.0.0.1:8000/polls/ in your browser and click the question link. You should see the following:

Select an option and click Vote . You will see a stub page with the "You are voting on question 1" message. That happens because we only have a dummy implementation of the vote() function in /polls/views.py . Let’s create a real one.
Open /polls/views.py and replace the vote() function definition with the following one:
This key elements of the above code are:
request.POST[‘choice’] returns the ID of the selected choice.
The except block is used to redisplay the question with an error message if no choice is provided.
HttpResponseRedirect redirects the user to a URL returned by the reverse() function.
The reverse() function is used to avoid hardcoding the URL. It accepts the name of the view that we want to pass control to and returns the URL of the voting results for the question.
Don’t forget to update the import statements in /polls/views.py as follows:
Now, if you go to http://127.0.0.1:8000/polls/ again and answer the question, you should see the following:

Here we are!
Now all features of our application work as designed. You can use the admin site to add as many questions as you like. While the Django server is running, you can access the list of questions at http://127.0.0.1:8000/polls/ and vote as many times as you like:

As you may have noticed, our app has a usability problem. When you click Vote again , it redirects you to the same question. A link to the list of all questions would be much more helpful. How do you fix that?
Check yourself
Edit the last line to get the following:
Testing the application
Now let’s see how PyCharm helps simplify testing your application.
There is already the file tests.py in the polls directory. By now, this file is empty. Naturally, it is advisable to place the new tests in this particular file. For example, we’d like to make sure our poll is not empty:
To run this test, right-click the background of the file tests.py in the editor, choose the option Run , or just press Ctrl+Shift+F10 . PyCharm suggests two options: to run UnitTest (which is defined as the default test runner), or a Django test.
The test results show in the Test Runner tab of the Run tool window:

Summary
This brief tutorial is over. You have successfully created and launched a simple Django application. Let’s repeat what you managed to do with the help of PyCharm:
Configure PyCharm for Python/Django and Introduction to Django Rest Framework
Working on a Django Project without a good support from an IDE could be a real pain. PyCharm is the most loved of all. Is has lots of features out of the box making your development process faster and efficient.
We’ll have a quick walkthrough to configure your development environment so that you can get the most out of PyCharm. Also, we’ll go through the basics of Django Rest Framework.
Prerequisites:
- You must have PyCharm Professional version as the Community version doesn’t have much advanced features. You can get a free education license if you are a student.
- Knowledge of Python/Django is recommended but not mandatory. We will start by setting up a new Django project.
Creating Django Project
- Open PyCharm Professional and click on Create New Project.
2. Choose Django on the left (this is something people usually forget). Now, select your project’s Base Directory. Don’t try to play with Project Interpreter yet. We’ll set it up later.
3. Click on More Settings and it’ll give some other useful options. Make sure you checked Enable Django Admin. Also, type in your Application Name.
4. Click on Create and PyCharm will create your Django App for you.
Creating Virtual Environment
5. Go to File -> Settings and select Project Interpreter. On the right of Project Interpreter, click on the settings symbol and select Add.
6. Select New environment and choose Location for the environment and your Base interpreter as your Python version (I am using Python 3.6) and click OK.
7. You’ll be redirected back to the settings menu. Now, select Show All from the right settings symbol.
8. This will give you a list of Virtual Environments. Select the one you created earlier and click OK.
Starting Django App Server
9. Let’s witness the power of Terminal inbuilt in PyCharm. Click on the Terminal tab below and you’ll see that the virtual environment is already activated . Its time to install Django using pip. Run pip install django.
10. Now go to Tools -> Run manage.py Task… Here you can run all the manage.py commands just by typing in their [options]. Run makemigrations inside manage.py@YourApp.
11. Now run migrate to create schema in your SQLite database.
12. Press the play button on the top to start your server. This is same as running python manage.py runserver.
13. Open localhost in your browser to see your working demo app.
14. Now, let’s run the app in PyCharm’s Debug Mode by pressing the bug symbol on the top.
Introduction to Django Rest Framework
15. Install Django Rest Framework. Run pip install django-rest-framework.
16. Don’t forget to add ‘rest_framework’ in the list of installed apps in settings.py
17. Create a Tech Model in models.py.
Models.py
18. Create a file named serializer.py inside your app directory and make a model serializer.
Serializer.py
19. Now, write two class-based views inside views.py. One returns a list of all the entries and the second returns a single entry.
- List API View —Inherit from this class to list all the entries. Also, you can use this view to create a post function that will allow creating a new entry in the database.
- API View — Inherit from this class if you want to perform CRUD operations (Create, Read, Update and Delete). I used this class to read and delete entries from the database.
Views.py
20. Now add routes for your views in urls.py. Note that now we don’t have a URL function instead we have path and re_path in Django 2.0.
Urls.py
21. Start your server in Debug mode again and visit your localhost in your browser to see Django Rest List API view. Add some test entities.
22. Entities will be added to list view as shown.
23. Now go to the Object View to get a single entity with its id.
Connect your Database to PyCharm
24. Let’s configure your database with PyCharm so that you’ll have a watch over your data. Click on the Database tab on the right and press Alt+Insert. Select Data Source -> SQLite ( Choose the database which is connected to your project but obviously you can connect to any database you want)
25. Choose the location of SQLite file.
26. Click on Test Connection to verify their are no errors. Click OK if the test was successful.
27. Now you can view the schema of your database and view the tables as well.
Making a Debug Point
28. Let’s test the debugging skills of PyCharm. Make a debug point by clicking on just right next to the line number. I have made a debug point inside delete method so this method will get paused at the debug point. Run your server in Debug mode again.
29. Go to TechView url and delete any entity. (Remember you have to open API View url and not the List View as we wrote our delete method inside TechView)
30. You’ll be redirected to PyCharm automatically as soon as the flow reaches the debug point.
Look at the window below. Its the most helpful window for debugging. It gives you all the info of variables and change in the value of those variables as the flow of code continues. Click on Step Over button (down symbol) to go the next line of code.
31. As you press Step Over the debugger state moves to the next line of code. Notice the added variables including tech. Now, click Resume Program button (next button) to move onto the next Debug point. As we placed only one Debug point, the program will finish execution.
Creating Django Applications on PyCharm is really fun and many Django Developers already use it. Try it out and give your thoughts in comments.
Step by Step Guide to Install and Setup Django Project in PyCharm
In this tutorial, we will focus on how to install and setup Django project in PyCharm IDE for application development. There are so many other IDEs available to do the same job like ATOM, Spyder, VC studio etc. Django is one the most demanded open source python web framework. It basically contains collection of python libraries which can be directly imported and used for developing web applications. It can be used to develop both front end and back end applications. It is one of the most in-demand python framework because of its ease to use and pragmatic design. More on Django Docs.

Step by Step Guide to Install and Setup Django Project in PyCharm
Step 1: Prerequisites
a) You should have a running Windows 10 machine.
b) You should have access to Install New Software.
c) You should have access to Microsoft Store .
Step 2: Create Normal Project
Open the IDE and create a normal project by selecting File -> New Project . Here name the project as “DjangoProject”

Step 3: Install Django
Next we will install Django module from terminal. We will use PyCharm integrated terminal to do this task. One can also use cmd on windows to install the module.
Step 4: Check Installed Django version
To check installed Django version, you can run python -m django -version command as shown below.
Step 5: Install mysqlclient(optional)
If you are working on some project which requires MySQL DB connection, then you need to install mysqlclient module to connect to MySQL database during the application development. You can install the module by using pip install mysqlclient command as shown below.
Once Installed, verify the installed modules by selecting File -> Settings -> Project Interpreter .

Step 6: Create Django Project
When you execute django-admin startproject command, then it will create a Django project inside normal project which we already have created here.
Once created, you should be able to see below folder structure with default files inside it.

Step 7: Check Python3 version
If you are going to use default Django web server, then you need to make sure python3 is installed. To check if it is installed or not, you can quickly run python3 —version command as shown below.
As you can see from above output, currently it is not installed. So to install it, run python3 command and it will redirect you to Microsoft Store from where you can directly install.
Once python3 is successfully installed, it should give you the right output as shown below.
Step 8: Run Default Django web server
Django internally provides a default web server where we can launch our applications. By default the server runs on Port 8000 . Access the web server on the highlighted URL.
If everything goes well, hit the above highlighted URL which will redirect you to below Django Home page.

Step 9: Run web server on different port
In case you don’t want to run your server on default Port 8000 , then you have the option to run on different port as well. Let’s say you want to use Port 9999 , so in that case you need to use python manage.py runserver 9999 command as shown below.

We have successfully done the set up !!
1 thought on “Step by Step Guide to Install and Setup Django Project in PyCharm”
Your step-by-step guidance for dango project is very easy and clear. I followed these stpes and
successfully created my first project and run the server. I thank you much for instructions..