How to create a Django project?
Last Updated :
04 Sep, 2023
Dive into the world of web development with Python by exploring the versatile Django framework. Django is a go-to for many developers due to its popularity, open-source license, and robust security features. It enables fast and efficient project development. In this tutorial, we will guide you through the process of installing Django on a Windows machine using pip, verifying the installation, creating a new project, and launching a Django development server. Get ready to enhance your web development skills and experience the power of Django.
Create a Project in Django
Before you begin, you will need to have the following:
Step 1: Opening PowerShell
The first step is to open PowerShell. To do this, press the Windows key and type PowerShell. Right-click on the PowerShell icon and select Run as Administrator.
PowerShell
open PowerShellStep 2: Verifying Python Installation
Once PowerShell is open, you can verify that Python is installed by typing python --version. This will display the version of Python that is installed.
Terminal command:
python --version
Python is installedStep 3: Upgrading PIP
Next, you will need to upgrade pip. To do this, type python -m pip install --upgrade pip. This will ensure that you have the latest version of pip installed.
upgrade pipStep 4: Creating a Project Directory
Now, you will need to create a project directory. To do this, type mkdir myproject. This will create a directory called myproject.
(i) Create the directory by utilizing the mkdir command. This command is a powerful tool that allows you to quickly and easily create a directory in your system. With this command, you can create a directory in seconds, making it a great time-saver for any user.
mkdir django_project
Create the directory(ii) Navigate to the Django_Project directory using the `cd` command. Here, you'll find all the necessary components to get your project up and running.
cd django_project
Django_Project directoryStep 5: Creating the Virtual Environment
Next, you will need to create a virtual environment. To create a virtual environment called myproject.
To do this, type in terminal
python -m venv myproject
python -m venv myproject and lsStep 6: Activating the Virtual Environment
Now, you will need to activate the virtual environment. To do this, type
venv\Scripts\activate
activate the virtual environmentStep 7: Installing Django
This section will teach you how to install Django on your system using pip. To do this, run the following command:
pip install Django
This will install the latest version of Django, allowing you to start building powerful web applications easily.
Installing DjangoIf you wish to install a different version of Django, you can easily specify the version you desire by following these steps:
pip install django
version of DjangoOnce the installation is complete, you must verify that Django has been successfully installed. To do this, enter the following command:
django-admin --version
Django versionStep 8: Create the Django Project
Now it's time to create a project. According to the Django documentation, a project is a Python package - i.e. a directory of code - that contains all the settings for an instance of Django. This includes database configuration, Django-specific options, and application-specific settings.
To create the project, use the command-line utility django-admin that comes with Django. This command will generate files where you can configure the settings for your database, add third-party packages, and more.
Create the project using the following command:
django-admin startproject test_project
Change into the test_project directory:
cd test_project
Type the following command to see the contents in the project directory:
ls test_project
Output:
output
The directory test_project contains Django configuration files. The manage.py file is especially useful when starting a development server, which is what you will do in the next step.
Step 9: Running the Development Server
Now that the project has been created, it's time to start the Django development server.Start the development server using the manage.py runserver command:
Note: Make sure sure you are in the same directory as manage.py file after to run manage.py runserver
python manage.py runserver
StartNow, Go to http://127.0.0.1:8000/ in your web browser. You should see a page similar to the following screenshot:
.png)
Conclusion:
You have come to the end of this article. You learned how to install Django on Windows, verify the installation, and you also learned how to create a Django project and start a development server.
Step 10: Create app in django
Now as we created the project in django and our django server is up and running and if now to create app in django project we can achieve it b by using django inbuit command which will initiate the django app for us.
Note: Make sure before running the command we must inside our project directory if not then run the below command
cd test_project
now we are inside the test_project and we are ready to create django app
django-admin startapp test_app
Now this command will create app inside our project and we ready to go with the django project and to know more about django app you can refer to the article - How to create app in django.
Similar Reads
How to Create an App in Django ?
In Django, an app is a web application that performs a specific functionality, such as blog posts, user authentication or comments. A single Django project can consist of multiple apps, each designed to handle a particular task. Each app is a modular and reusable component that includes everything n
3 min read
How to Create a Basic Project using MVT in Django ?
Prerequisite - Django Project MVT Structure Assuming you have gone through the previous article. This article focuses on creating a basic project to render a template using MVT architecture. We will use MVT (Models, Views, Templates) to render data to a local server. Create a basic Project: To in
2 min read
How to create superuser in Django?
Django comes with a built-in admin panel that allows developers to manage the database, users and other models efficiently. This eliminates the need for creating a separate admin interface from scratch. To access and manage the Django Admin panel, we need to create a superuser i.e. a user with full
2 min read
Connect Django Project to MongoDB
Djongo is a SQL to MongoDB query transpiler. Using djongo, we can use MongoDB as a backend database for our Django project. We don't even need to change the Django ORM. The best part is that we can setup Django with MongoDB by adding just one line of code. There is no need to change serializers, vie
2 min read
Django Introduction | Set 2 (Creating a Project)
Note- This article is in continuation of Django introduction. Popularity of Django Django is used in many popular sites like as: Disqus, Instagram, Knight Foundation, MacArthur Foundation, Mozilla, National Geographic etc. There are more than 5k online sites based on Django framework. ( Source ) Si
3 min read
How to Connect Django with Reactjs ?
Connecting Django with React is a common approach for building full-stack applications. Django is used to manage the backend, database, APIs and React handles the User Interface on frontend. Prerequisites:A development machine with any OS (Linux/Windows/Mac).Python 3 installed.Node.js installed (ver
9 min read
How to create user from Django shell
Let's look at how to create a user for Django using Django's interactive shell? Make sure you have the virtual environment activated, and you are within the folder that has the manage.py file. Note: Refer to the article How to Create a Basic Project using MVT in Django? to understand how to create
1 min read
How to create a form using Django Forms ?
Django forms are an advanced set of HTML forms that can be created using python and support all features of HTML forms in a pythonic way. This post revolves around how to create a basic form using various Form Fields and attributes. Creating a form in Django is completely similar to creating a model
3 min read
How to create a new project in Django using Firebase Database?
Django is a Python-based web framework that allows you to quickly create efficient web applications. If you are new to Django then you can refer to Django Introduction and Installation. Here we are going to learn How to create a Django project using Firebase as Database . How to create a new projec
3 min read
How to Render Data in Django
Django's render() function is a fundamental tool for building dynamic web applications. It simplifies the process of combining HTTP requests with HTML templates and dynamic data, making it easier for developers to create interactive and data-driven web pages. What is render()?In Django, the render(
3 min read