Django / Django Installation and Setup

Creating a New Django Project

This tutorial will walk you through the process of creating a new Django project. You'll learn how to use Django's command-line tools to generate a new project with all the necess…

Tutorial 3 of 5 5 resources in this section

Section overview

5 resources

Explains how to install and set up Django on different platforms and environments.

1. Introduction

In this tutorial, we will learn how to create a new Django project from scratch. Django is a high-level Python web framework that promotes rapid development and clean, pragmatic design.

We will cover how to:

  • Use Django's command-line tools to create a new project
  • Understand the structure of a Django project
  • Explore the configuration files generated by Django

Prerequisites:

  • A basic understanding of Python programming
  • Django installed on your system. If it's not installed, you can do so by running pip install Django in your terminal.

2. Step-by-Step Guide

2.1. Creating a New Django Project

A Django project is a collection of settings and configurations for an instance of Django, including database configuration, Django-specific options, and application-specific settings.

To create a new Django project, navigate to the directory where you want your project to live, and run the following command:

django-admin startproject my_project

Replace my_project with your preferred project name. Django will create a new directory with the same name as your project, which will contain the basic files and directories necessary for a Django project.

2.2. Understanding the Django Project Structure

After running the above command, your project directory should look like this:

my_project/
    manage.py
    my_project/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

Here's what each file does:

  • manage.py: A command-line utility that lets you interact with your Django project.
  • my_project/: The inner my_project/ directory is the actual Python package for your project.
  • __init__.py: An empty file that tells Python that this directory should be considered a Python package.
  • settings.py: Settings/configuration for this Django project.
  • urls.py: The URL declarations for this Django project.
  • asgi.py: An entry-point for ASGI-compatible web servers.
  • wsgi.py: An entry-point for WSGI-compatible web servers.

3. Code Examples

3.1. Running the Django Development Server

To verify that your project has been set up correctly, navigate to your project directory (my_project/) and run the following command:

python manage.py runserver

This command starts the Django development server, which is a lightweight web server written purely in Python. After running the command, you should see output similar to the following:

Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

You can now open your web browser and visit http://127.0.0.1:8000/ to view your new Django project.

4. Summary

In this tutorial, we learned how to create a new Django project, explored the structure and purpose of various files in a Django project, and ran our project using Django's development server.

For further learning, you can explore how to create and manage Django applications, how to connect Django to a database, and how to use Django's models and views to design your website's backend.

5. Practice Exercises

  1. Create a new Django project in a different directory and compare its structure with the one we created in this tutorial.
  2. Modify the settings.py file in your new Django project to change the timezone to your local timezone. (Hint: Look for the TIME_ZONE setting.)
  3. Use the Django development server to run your new Django project and visit it in your web browser.

Solutions:

  1. The structure of the new Django project should be identical to the structure of the project we created in this tutorial.
  2. Open settings.py and find the TIME_ZONE setting. Change its value to your local timezone, for example, 'America/New_York'.
  3. Navigate to your project directory and run python manage.py runserver. Open your web browser and visit http://127.0.0.1:8000/.

Keep practicing and exploring Django to become more comfortable with it. Happy coding!

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Meta Tag Analyzer

Analyze and generate meta tags for SEO.

Use tool

Text Diff Checker

Compare two pieces of text to find differences.

Use tool

Color Palette Generator

Generate color palettes from images.

Use tool

CSS Minifier & Formatter

Clean and compress CSS files.

Use tool

PDF Compressor

Reduce the size of PDF files without losing quality.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help