What’s the difference between a project and an app in Django world?

A project refers to the entire application and all its parts.

An app refers to a submodule of the project. It's self-sufficient and not intertwined with the other apps in the project such that, in theory, you could pick it up and plop it down into another project without any modification. An app typically has its own models.py (which might actually be empty). You might think of it as a standalone python module. A simple project might only have one app.

For your example, the project is the whole website. You might structure it so there is an app for articles, an app for ranking tables, and an app for fixtures and results. If they need to interact with each other, they do it through well-documented public classes and accessor methods.

The main thing to keep in mind is this level of interdependence between the apps. In practice it's all one project, so there's no sense in going overboard, but keep in mind how co-dependent two apps are. If you find one app is solving two problems, split them into two apps. If you find two apps are so intertwined you could never reuse one without the other, combine them into a single app.


Lets understand Project and App in Django with this realistic example:

Say you are building an online shopping site (e-commerce site) in Django:

Project:

Its simply name of your website. Django will create a python package and give it a name that you have provided. lets say we name it my_shopping_site.

You can create a project in Django with this command

python manage.py startproject my_shopping_site

This will create my_shopping_site directory in your working directory and the structure will look like this:

my_shopping_site/
   manage.py
   my_shopping_site/    # package
        __init__.py     # indication of package
        settings.py     # module 1
        urls.py         # module 2
        wsgi.py         # module 3

Apps:

Its those little components that together make up your project. They are the features of your project. In our case (shopping site) it would be:

  • Cart :- Which would have a logic for user selected items for purchase.

  • Products :- Which would have a logic for products that the site is selling.

  • Profile:- Which would have a logic for user information.

    -----------------------------------------------------------
    my_shopping_site              Products     Profile     Cart
    -----------------------------------------------------------
    

and you can create these apps with these commands:

python manage.py startapp cart
python manage.py startapp products
python manage.py startapp profile

The structure would look like this:

my_shopping_site/   # project name
      manage.py
      products/          # app 1
      cart/              # app 2 
      profile/           # app 3
      my_shopping_site/

each app focus on a single logical piece of your project.


Ideally, your project should be composed by apps. That's why when using the command line, you create a project, an later on, add apps to that project.

Apps, aims to bring modularity to your project. For example, if you build an articles app, ideally, you can use it in your sports news project, and re-use it in a new project which requires it with minimum or no modification to its settings -- say a blog project, for example.

Apps are piece of software meant to be reused. Your project stands only for your very specific needs.

Take a look at Django Project Structure. It may give you some insight in the best practice of organizing your Django project.

There are also several blog posts searchable on Google that address this topic:

  • http://timmyomahony.com/blog/updated-django-project-structure-or-folder-layout/
  • http://www.revsys.com/blog/2014/nov/21/recommended-django-project-layout/

Tags:

Python

Django