When to create a new app within a Django project structure?
Asked Answered
K

1

6

I have seen other questions on stackoverflow (When to create a new app (with startapp) in Django?) and read some slides on the topic but still am a little confused on when to create a new app in a Django project? I am coming over from a MEAN stack and I am new to Django.

If I want to create a web application with the following four main features:

-Register

-Login

-Chat with other users

-Upload files

Will these be 4 separate apps with their own views.py, urls.py, etc.? Or do I create 1 app and they share app files?

It seems that 'apps' in Django projects are described as reusable modules, but these features would only be used once in my whole web application so they would not be reusable?

If I wanted to build two completely separate websites, do I create 2 separate Django projects or 1 project with separate apps inside of it and would reuse an app such as registration?

Just trying to wrap my ahead around how to structure this.

Below is from Django's poll tutorial:

Projects vs. apps

What’s the difference between a project and an app? An app is a Web application that does something – e.g., a Weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.

The part I bolded confuses me very much on how to structure and when to separate apps.

Any help is appreciated.

Kitsch answered 27/5, 2017 at 2:13 Comment(0)
C
4

Many will raise the same question when they are new to Django. just to be clear I have used django version 1.9 and 1.10 so if you are using version <=1.8 some concept may change.

In django you can create separate app for module which you need to be used in some other modules frequently. all the four feature you need can be used in one single app but let assume you want your chat functionality which is useful in many apps for help & support service or to create chat bot (mostly people uses chat sservice in their website from different source) in such case if you have multiple uses of the specific feature or you want to provide someone to use your chat service with your API it's preferable to create separate app for it. Now if you talk about register and login feature it's available in django built-in module django.contrib.auth so you can create single app for it. If we talk about upload files functionality it can be used in your chat application and others but instead of creating seperate app for it you can implement it in same form, view and model or you can just create another separate python script which you can invoke in view or model anytime when you want to use using inheritance or your preferable method.

Concourse answered 27/5, 2017 at 2:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.