Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to create a new app (with startapp) in Django?

Tags:

python

django

People also ask

What does Startapp do in Django?

The startapp command in Django is used to create a new app with our project. Now, we can use this command multiple times within our project to create multiple apps. By executing this command, Django automatically creates the application directory in the project directory.

What is the difference between Startproject and Startapp in Django?

The startproject will create the main project directory, while the startapp will create the app directory. Both are also been passed a name to be used in generation. The startproject is the first command run when creating a new project, while the startapp is run inside the new project directory.

How many apps should a Django project have?

Django comes with six built-in apps that we can examine.


James Bennett has a wonderful set of slides on how to organize reusable apps in Django.


I prefer to think of Django applications as reusable modules or components than as "applications".

This helps me encapsulate and decouple certain features from one another, improving re-usability should I decide to share a particular "app" with the community at large, and maintainability.

My general approach is to bucket up specific features or feature sets into "apps" as though I were going to release them publicly. The hard part here is figuring out how big each bucket is.

A good trick I use is to imagine how my apps would be used if they were released publicly. This often encourages me to shrink the buckets and more clearly define its "purpose".


Here is the updated presentation on 6 September 2008.

DjangoCon 2008: Reusable Apps @7:53

Slide: Reusable_apps.pdf

Taken from the slide

Should this be its own application?

  • Is it completely unrelated to the app’s focus?
  • Is it orthogonal to whatever else I’m doing?
  • Will I need similar functionality on other sites?

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


I tend to create new applications for each logically separate set of models. e.g.:

  • User Profiles
  • Forum Posts
  • Blog posts