Projects and applications in Django

- Andrés Cruz

En español
Projects and applications in Django

In Django, we have to be clear about two key concepts, a project and an application.

A project in Django consists of one or many applications; that is, to be able to do something interesting in our project, we must have at least one application.

A project is a collection of settings and applications for a particular website. A project can contain multiple applications. An app can be in multiple projects.

An application in Django is a web application that does something, for example, a web registration system, a public records database, a Rest API, an app for selling something, etc.

In conclusion, the project contains the applications and configurations at a global level, such as the database, installed applications, middleware, templates, etc. and the applications are the ones that carry out the functions that we implement.

The use of Django to create applications is strongly linked to the modularization concept, and therefore, we can create multiple small applications that perform particular tasks, so that together, we can have the final application that we want; for example, for a blog type application:

  1. An application for the list and detail of the posts.
  2. An application to handle authentication, registration and derivatives.
  3. An application to manage contacts, as well as manage post comments and others.
  4. An application to handle a rest api.
  5. An application to manage basic information, such as contact and "about".

The above list is an outline, and we didn't put the full description of what each app would do.

So, ultimately, the idea is to modularize our application (using the application concept as the final product); you don't have to follow this structure to the letter, you can add, remove or merge applications, but always keep in mind that the more modular the better the scalability and maintenance of the project.

Create a project in Django

To create a project in Django, we have the following command:

$ python startproject mystore

This will finally generate the set of folders and files that make up a Django project that we are going to explain next.

It is important to note that “mystore” is the name of the project that we are going to create, but it can have any other name.

Project structure

If you execute the previous command, you will see that a set of folders and files are created that we are going to explain.

These files are:

The root folder mystore/ (or whatever name you chose to create the project): This is just the container for the project; here are the settings and applications. A command line utility that allows you to interact with this project.

mystore/ An empty file that tells Python that this directory should be considered a Python module.

mystore/ Settings or configuration for this project.

mystore/ The URL declarations for the project.

mystore/ Configuration file to serve the project on an ASGI type server.

mystore/ Configuration file to serve the project on a WSGI-type server.

Andrés Cruz

Desarrollo con Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz en Udemy

Acepto recibir anuncios de interes sobre este Blog.