Creating Your First Django Project


Introduction

Django is a powerful web framework for Python that simplifies web development. In this guide, we'll walk you through the process of creating your first Django project step by step.


Prerequisites

Before you begin, make sure you have the following prerequisites installed on your computer:

  • Python: Install the latest version of Python from python.org.
  • Pip: The Python package manager comes with Python. You can check if it's installed by running
    pip --version
    in your command prompt or terminal.

Installing Django

To create a Django project, you first need to install Django. You can do this using pip, the Python package manager. Open your command prompt or terminal and run the following command:

pip install django

Creating a Django Project

Once Django is installed, you can create your first project. Navigate to the directory where you want to create your project and run the following command:

django-admin startproject projectname

Replace "projectname" with the name of your project.


Project Structure

Your Django project will be created with a basic directory structure. Here's what the key directories and files contain:

  • projectname/: The root directory of your project.
  • manage.py: A command-line utility to manage various aspects of your project.
  • projectname/: The inner project directory contains your project's settings and configuration.

Running the Development Server

To run your Django project locally, navigate to the project directory and execute the following command:

python manage.py runserver

You can access your project at http://127.0.0.1:8000/.


Conclusion

Congratulations! You've successfully created your first Django project. You can now start building your web application and explore the world of Django development.