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

2

I had done some testing as a Django framework a while ago, and only now that I've tested it again, I noticed that there are two commands that have confused me:

django-admin startproject nome_do_projeto

And we also have:

django-admin startapp nome_do_app

I do not remember needing to use the command django-admin startapp of the last few times I used it. Is this a new option?

I have some questions to ask:

  • What's the difference between one and another?

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

  • Are there any structure differences?

asked by anonymous 05.04.2017 / 03:09

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.

  • The parent directory mysite is where everything will be organized. The project and the 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's 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 internal mysite directory, in turn, is the Django project created. Since the definition in the glossary states that the project is a Python package (a code directory) that contains all the settings of the Django instance in question. It can also contain database settings, general application settings, and more.

The project itself does not do much because, in Django's philosophy, a project should be composed of applications.

apps , in turn, can be defined as a set of interrelated features that are defined to create or maintain an aspect of the project. In general, apps are set to be as reusable as possible, and are charged with only a very specific function. It is also considered that the apps will be, to the maximum, independent of each other - being dependent only when it really makes sense.

For example, if your application (project) will need a Blog area, you'll create an app for it, but for ONLY 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 , okay, but do it in another app. Do not have a user management system? Another app. In other words (which are almost the same), apps are responsible for denying aspects of the application / project and can be reused in as many projects as needed.

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

  

Remember that Django is a Python package installed on the server, so it's the same code being run by the various sites that may be hosted on it, so it says about the instance of the Django.

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

    
05.04.2017 / 03:48
1

You can have multiple applications 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 the user accounts, This App and provided by django itself, there you can create your with your purposes so as to meet project needs

    
06.04.2017 / 16:20