Setting Up a New Python Django Project: A Step-by-Step Guide to Establishing a Proper Directory Structure | Live Demo

Posted by

Python Django Basics – How to Set up a New Project with a Proper Directory Structure | Live Demo

Python Django Basics – How to Set up a New Project with a Proper Directory Structure

Django is a powerful web framework for building web applications quickly and efficiently. Setting up a new Django project with a proper directory structure is essential for maintaining a clean and organized codebase. In this article, we will cover the basic steps to set up a new Django project.

Step 1: Installing Django

First, make sure you have Python installed on your system. You can install Django using pip, the Python package manager, by running the following command:

pip install django

Step 2: Creating a New Django Project

To create a new Django project, run the following command in your terminal:

django-admin startproject myproject

This will create a new directory called myproject with the following directory structure:

  • myproject/
    • manage.py
    • myproject/
      • __init__.py
      • settings.py
      • urls.py
      • wsgi.py

Step 3: Setting up the Directory Structure

It is best practice to organize your Django project files into separate directories for better maintainability. Here is a recommended directory structure for a Django project:

  • myproject/
    • apps/
      • __init__.py
      • myapp/
        • __init__.py
        • models.py
        • views.py
        • urls.py
        • templates/
        • static/
    • config/
      • __init__.py
      • settings.py
      • urls.py
      • asgi.py
      • wsgi.py
    • static/
    • templates/

Live Demo

For a live demo of a Django project with a proper directory structure, you can check out the repository here.