Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django : Why should I add package name inside INSTALLED_APPS?

Tags:

python

django

In Djano, why should I add third-party package names inside the INSTALLED_APPS for some packages such as django-filter, DRF, debug-toolbar etc, while I don't want to add for some packages such as Celery, Requests etc ?

I couldn't figure out why should add them to a specific list, even though they all are similar pip packages and I installed them in the same way.
Thanks in advance!

like image 381
JPG Avatar asked Sep 20 '25 11:09

JPG


1 Answers

From docs :

Package? App?

A Python package provides a way of grouping related Python code for easy reuse. A package contains one or more files of Python code (also known as “modules”).

A package can be imported with import foo.bar or from foo import bar. For a directory (like polls) to form a package, it must contain a special file init.py, even if this file is empty.

A Django application is just a Python package that is specifically intended for use in a Django project. An application may use common Django conventions, such as having models, tests, urls, and views submodules.

From above statements we understand that every well-written python code could be a package, now if this package is a bunch of python code in a directory, installing it would mean just copy the directory in your project and import them wherever needed in code.

But now there is this package which was already a django app and maybe used some special advantages of being one. Like exposing a restful API or delivering some sort of static resources or even working with special django-specific classes. these kind's of operation's need your direct permission in settings.py so that your project will know how to deal with this package. or even they may require to include their url path's to your project so that people visiting your site could access them.

I assume all this manual job is an act of security.

like image 125
AmiNadimi Avatar answered Sep 22 '25 01:09

AmiNadimi