Free Ebook cover System creation course with Python and Django complete

System creation course with Python and Django complete

New course

176 pages

Creating a Django Project: Structure of a Django Project

Capítulo 60

Estimated reading time: 3 minutes

Audio Icon

Listen in audio

0:00 / 0:00

Django is a high-level web development framework, written in Python, that promotes rapid development and clean, pragmatic design. It comes with a number of ready-to-use tools and functionality that can help developers create robust and efficient web applications. This course chapter will guide you through the process of creating a new Django project and explore the structure of a Django project.

Creating a new Django project

To create a new Django project, you must first have Django installed on your system. If you already have Django installed, you can create a new Django project using the following command:

django-admin startproject project_name

This command will create a new directory with the name you gave your project. This directory is the root of your Django project and contains all the files needed for your project.

Structure of a Django project

A Django project is made up of a set of settings for an instance of Django, including database configuration, Django-specific options, and application-specific settings. Let's take a look at the default structure of a Django project.

project name/
    manage.py
    project name/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

Here is a brief description of each of the files and directories:

Continue in our app.

You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.

Or continue reading below...
Download App

Download the app

  • manage.py: This is a command line utility that lets you interact with your Django project in a variety of ways. For example, you can use this file to create tables in your database or start a web server for your project.
  • project_name/__init__.py: This is an empty file that tells Python that this directory should be considered a Python package.
  • project_name/settings.py: This file contains all the settings for your Django project. You will reference this file whenever you need to change something related to your project's configuration.
  • project_name/urls.py: This file is used to define URL patterns for your project. In other words, this file tells Django which pages to display for which URLs.
  • project_name/asgi.py: This file is used to serve your project when it is deployed to an ASGI server. ASGI is the asynchronous server gateway specification that allows Django to handle asynchronous traffic.
  • project_name/wsgi.py: This file is used to serve your project when it is deployed to a WSGI server. WSGI is the web server gateway specification that allows Django to handle synchronous traffic.

This is the basic structure of a Django project. As you start adding applications to your project, you'll see more files and directories being added to this structure. However, the basic structure will remain the same.

In summary, creating a Django project involves creating a workbench, setting up a database, defining URLs, and creating views and models. The Django project structure is designed to be flexible and easy to expand, making it an excellent choice for projects of all sizes.

We hope this chapter has given you a clear understanding of creating a Django project and the structure of a Django project. In the next chapter, we'll dive deeper into Django application development.

Now answer the exercise about the content:

What is the role of the "settings.py" file in a Django project?

You are right! Congratulations, now go to the next page

You missed! Try again.

The settings.py file in a Django project contains all the settings and configurations for the project. It plays a crucial role in the project's configuration by managing settings like database configuration, installed applications, middleware, templates, and more.

Next chapter

Creating a Django Project: Database Setup

Arrow Right Icon
Download the app to earn free Certification and listen to the courses in the background, even with the screen off.