How to Create a Django Project

Before you can start building your Django web application, you need to set up your Django project. In this guide you’ll learn how to create a new Django project in four straightforward steps and only six commands:

Step Description Command
1a Set up a virtual environment python -m venv .venv
1b Activate the virtual environment source .venv/bin/activate
2a Install Django python -m pip install django
2b Pin your dependencies python -m pip freeze > requirements.txt
3 Set up a Django project django-admin startproject <projectname>
4 Start a Django app python manage.py startapp <appname>

The tutorial focuses on the initial steps you’ll always need to start a new web application.

Use this tutorial as your go-to reference until you’ve built so many projects that the necessary commands become second nature. Until then, follow the steps outlined below and in the command reference, or download the PDF cheatsheet as a printable reference:

There are also a few exercises throughout the tutorial to help reinforce what you’re learning, and you can test your knowledge in the associated quiz:

Take the Quiz: Test your knowledge with our interactive “How to Create a Django Project” quiz. You’ll receive a score upon completion to help you track your learning progress:


Django Setup Guide

Interactive Quiz

How to Create a Django Project

Check your Django setup skills. Install safely and pin requirements, create a project and an app. Start building your first site.

Prerequisites

Before you start creating your Django project, make sure you have the right tools and knowledge in place. This tutorial assumes you’re comfortable working with the command line, but you don’t need to be an expert. Here’s what you’ll need to get started:

You don’t need any prior Django experience to complete this guide. However, to build functionality beyond the basic scaffolding, you’ll need to know Python basics and at least some Django.

Step 1: Prepare Your Environment

When you’re ready to start your new Django web application, create a new folder and navigate into it. In this folder, you’ll set up a new virtual environment using your terminal:

Windows PowerShell

PS> python -m venv .venv

Shell

$ python3 -m venv .venv

This command sets up a new virtual environment named .venv in your current working directory. Once the process is complete, you also need to activate the virtual environment:

Windows PowerShell

PS> .venvScriptsactivate

Shell

$ source .venv/bin/activate

If the activation was successful, then you’ll see the name of your virtual environment, (.venv), at the beginning of your command prompt. This means that your environment setup is complete.

You can learn more about how to work with virtual environments in Python, and how to perfect your Python development setup, but for your Django setup, you have all you need. You can continue with installing the django package.

Step 2: Install Django and Pin Your Dependencies

Read the full article at https://realpython.com/django-setup/ »


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Liked Liked