Newbie Django: creating a project with multiple applications or all in one

I start in the world of Django, I developed some “information sites” (nothing complicated), but this week my boss ordered me to migrate large software with 7 modules.

So, I went to read the documentation page and search on Google how I could create this software using Django. I know that each “module” can be called an “application”, so I am creating a new project and one application for each module (I don’t know if it was right, because the modules will not be public).

The problem is that now I do not know what the next step is.

All my applications can exchange data (each application has its own models, but sometimes one application has a model associated with models in other applications)?

Where do I write code for the login process (I create a manageUsers application that was thought to handle registration, editing, sharing, and checking the profile of the current or new user), and we can share this session data through the applications?

Do I need another application for posting information on the site (for example, contact, pricing ...)? I am using Python 2.7, Django 1.3, Memcached and Mysql 5.

If someone can help me or tell me where it can clarify these questions, because most explain how to develop using only one application, and there was no answer in IRC, otherwise I have to write all the code in one application?

Best wishes

+4
source share
2 answers

A good place to start (dated, but worth reading, also look at the user comment bubbles): http://www.djangobook.com/en/2.0/ . Chapter 1 - 10 is an important reading. You can select and select the remaining chapters for reading if you wish.

Yes, all Django applications can exchange data with each other. You are making several Django applications hosted under a single Django project. The project creates a common database for use, and each application creates models that use the specified database. App1 can talk to App2 and vice versa.

Django Project (one) <----->> (many) Django Application 

You usually disable applications based on a common feature. User accounts have their own application (see the "Out" section below). Blogging has another. The Google Maps interface will get a different one. User subscription, another.

For user accounts and login, Django provides an Auth module . You can have user accounts stored directly in Django, or configure it to communicate with something else, such as Active Directory. Auth works “pretty well” out of the box, although I personally configured my bit to allow 255-character email addresses as usernames (by default it is limited to 40 characters). Chapter 14 in the Django book may be a little easier to read than the Auth white papers. If you use Auth, you do not need to create your own Django application, since Auth is already alone! You just set it to settings.py and you are golden.

Your Django structure will most likely look something like this:

 /Project/ __init__.py manage.py settings.py urls.py App1/ __init__.py forms.py models.py views.py templates/App1/ template1.html template2.html App2/ ... 

App2 can access App1 data models by doing: from Project.App1.models import someModel

+10
source

The rules are simple for me.

  • If you need to copy-paste the code from one project to another - make an application for it
  • If one of the modules of application modules is more than 1 thousand lines and / or difficult to maintain, find something to move in a separate application.
  • Group functionality in applications to minimize cross-linking between them.

For interconnection you can use signals and sessions

+2
source

Source: https://habr.com/ru/post/1401503/


All Articles