What is the difference between project ("project") and application ("app") in Django?

Asked

Viewed 593 times

2

I had done some tests as Django framework a while ago, and only now that I tested it again, I noticed that there are two commands, which ended up confusing me:

django-admin startproject nome_do_projeto

And we also have:

django-admin startapp nome_do_app

I don’t remember needing to use the remote django-admin startapp last time I used it. This is some new option?

I have some questions to ask:

  • What’s the difference between one and the other?

  • For Django, what is a "project" and what is an "application"?

  • There are differences in structure?

  • I have the small impression that something has changed, because I don’t remember the time I used to touch Django to have the script apps.py inside the project folder...

2 answers

4

First, let’s look at the directory structure that is generated when we create a project:

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

Project created with the command django-admin startproject mysite, for information purposes.

  • The parent directory mysite is where everything will be organized. The project and applications will be organized in this directory. At first, it is common for the developer to believe that this is the Django project created, but no, it is just a directory to separate everything from the rest of the files on the machine. So much so that the name of this directory is not important - it only takes the same project name by default.

  • The directory mysite internal, in turn, is the Django project created. Since the definition in the glossary it appears that the project is a Python package (a code directory) that contains all the settings of the Django instance in question. It may also contain database settings, general application settings, and more.

The project itself doesn’t do much, because in Django’s philosophy, a project should be composed of applications (app).

The apps (app), in turn, they can be defined as a set of interrelated functionalities that are defined to create or maintain an aspect of the project. In general, apps are set to be as reusable as possible, being tasked with only one very specific function. It is also considered that apps will be, at most, independent of each other - being dependent only when it really makes sense.

For example, if your application (project) will need a Blog area, you will create an app for it, but for JUST that. In this app you will define all necessary database table structures and all business rules for a blog to be functional.

But I want to create an access management system for users on my blog, ok, but do it in another app. Don’t have a user management system? Another app. In other words (which are almost the same), apps are responsible for denigrating the application/project aspects and can be reused in as many projects as needed.

Briefly, the project is responsible for configuring the instance of Django in question according to the needs of the application and has a set of apps that define the aspects of the application.

Remember that Django is a Python package installed on the server, so it is the same code being executed by the various websites that may be hosted on it, so it is said about the instance django.


Rebound, here, that in my view the best translation for the term app is application and not application, as this is usually used to refer to the set as a whole, while application expresses a less generalist idea.

1

You can have multiple apps within a project. Each App can take care of a different part of the project. For example, there is an App called admin that is already installed by defult in the project that serves , among other things, to manage user accounts, This App is provided by Django itself, There you can create yours with your purposes in order to meet the needs of the project

Browser other questions tagged

You are not signed in. Login or sign up in order to post.