When do I need to create a new application (with startapp) in Django?

I thought about this, but I still have problems with what Django defines as "applications."

Should I create a new application for each functionality on the site, even if it uses models from the main project?

Do you guys have a good rule when you need to separate a new application and when to keep functionality together with the "main project" or other applications?

+75
python django
Sep 15 '08 at 16:03
source share
7 answers

James Bennet has a wonderful set of slides on how to organize reusable applications in Django.

+37
Sep 15 '08 at 16:35
source share

I prefer to think of Django applications as reusable modules or components rather than “applications”.

This helps me to encapsulate and separate certain functions from each other, improving reuse if I decide to share a certain “application” with the community as a whole and with the possibility of maintenance.

My general approach is to embed certain functions or a set of functions in "applications" as if I were going to publish them publicly. The hard part here is how big each bucket is.

The good trick I use is to imagine how my applications will be used if they are published publicly. This often prompts me to squeeze buckets and more clearly define its “purpose”.

+16
Sep 15 '08 at 16:32
source share

I try to create new applications for each logically separate set of models. eg:.

  • User profiles
  • Forum Posts
  • Blog posts
+11
Sep 15 '08 at 16:12
source share

Here is the updated presentation on September 6, 2008.

DjangoCon 2008: reusable applications @ 7: 53

Slide: Reusable_apps.pdf

Taken from a hill

Should it be his own application?

  • Is this completely unrelated to application focus?
  • Is it orthogonal to what I'm doing?
  • Will I need similar features on other sites?

If any of them are "Yes"? Then it is better to break it into a separate application.

+9
Nov 07 '11 at 9:15
source share

The next rule is a new application if I want to reuse functionality in another project.

If you need a deep understanding of your project’s models, stick to the models more closely.

+4
Sep 16 '08 at 0:01
source share

An “application” can be many different things, it really comes down to taste. For example, let's say you are building a blog. Your application can be an entire blog, or you can have an “admin” application, a “site” application for all public submissions, an “rss” application, a “services” application, so that developers can interact with the blog in their own ways, etc.

I personally would make the blog my application and rip out the functionality inside it. The blog could then be reused on other websites.

The good thing about Django is that it recognizes any models.py file at any level of your directory tree as a file containing Django models. Thus, breaking your functionality into smaller “helper applications” inside the “application” itself will not complicate the situation.

+1
Sep 15 '08 at 22:56
source share

The two best answers to this question that I found on the Internet are:

  1. A discussion of reusable applications ( slides ) ( video ) is also mentioned in other answers. Bennett, author and contributor to Django, regularly publishes apps that others can use, and has a solid point of view on many small apps.
  2. Doordash Tips for Django in Scale, which gives the opposite advice and says that in their case they switched to the same application after starting with many separate applications. They are having problems plotting migration dependencies between applications.

Both sources agree that you should create a separate application in the following situations:

  • If you plan to reuse your application in another Django project (especially if you plan to publish it for reuse by other users).
  • If the application has few or no dependencies between it and another application. Here you can imagine an application working as its own microservice in the future.
0
Dec 12 '18 at 2:16
source share



All Articles