Project organization for multiple apps sharing the same frontend and templates

I have website which contains main pages like Homepage, About Me, Contact, Gallery, etc.
Additionally I added Blog pages and Courses pages but since they have their own models and logic I implemented them as separate Django apps.

So I ended up with 3 apps: my_app, blog_app, courses_app.

When I started with my_app, I just put all logic and all frontend part (jss, css, …) and templates into it.
Now I realized that blog_app and courses_app have to use the same frontend and templates as my_app. So I created templates in each blog_app and courses_app but they extend and use templates and frontend from my_app. So it looks like a total mess to me.

Now I’m starting a new project and would like to make it right this time.

So what would be the correct structure ?

I was thinking to create this apps:

  • core_app - which contains frontend (css, jss) and html templates for a website
  • main_pages_app - which contains models, views, logic, etc. for most of the website pages. It contains also admin.py to manage the models.
  • blog_app - which contains models, views, logic, etc. for blog. It contains also admin.py to manage the models.
  • courses_app - which contains models, views, logic, etc. for courses. It contains also admin.py to manage the models.

Regarding templates in main_pages_app, blog_app, courses_app, I’m thinking of 2 ways to go:

  • each app will contain templates which extend from base templates located in core_app or
  • all html part will be written in core_app templates (other apps will then just pass the data to this templates).

Does this idea make sense ?
Is there a better approach to that ?

Thanks!

There is a very lengthy discussion on this topic here: Why do we need apps? It’s worth reading the entire thread.

My short answer to this is that my default is to always build my project as one app unless some condition exists to indicate otherwise.

For example, if I’m building a component to be used in multiple projects, then I want to structure it in such a way that it can be used as an app. If I know I’m going to be working on a Large system, my initial plans are likely to include multiple apps. (Large in my case typically refers to a system with more than 100 models or a projection of 10,000 lines of code.) But other than that, pretty much everything I build is built as a single app.

2 Likes

Thanks, I have already read suggested article before posting this question :slight_smile:.
And was not convienced that I should use multiple apps at all that’s why I posted this question.
But now with your comment I think I’ll definitely go with single app for my needs (solo developer making small projects).