W
W
WebDeveloper20162016-11-21 16:45:05
Django
WebDeveloper2016, 2016-11-21 16:45:05

Why are applications needed?

I just can’t enter why is the division of the project into applications introduced into django at all? Those. in the same place, startproject is first made, and then startapp is also made in it. And how to understand, so to speak, where one application ends and another begins? And then I seem to be doing everything in one now.
upd. Once again, if I understand correctly, the following project structure would be optimal:
ca52d5d8fac8499c86a6283d12716211.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2016-11-21
@WebDeveloper2016

А что с главной страницей?
создай апп с названием core || common || main || etc и сделай там вью со своей главной
Т.е. сама основа на которой хедер, футер и в нее уже контент этих приложений вставляется.
основа верстки ложится в темплейт, основа контекста, может ложится в core
Ее что отдельным приложением сделать?
если какая-то часть задачи сильно отличается от дргуих - ее можно вынести в апп
В общем случае, нужно стараться делать такие аппы, которые можно поместить в пакет и переиспользовать в другом проекте, но не проблема, если так не получается

Артём Брюханов, 2016-11-21
@drupa

The project is your site, mysite.ru. In which settings are configured in the settings.py file, urls in urls.py.
Applications are part of the site's logic, for example: articles - where, let's say, everything is stored that relates to articles on your site, templates in the templates folder, model descriptions in the models.py file, and view output in views.py.
And the number of applications in your project can be very large, for example, a shopping cart, user profile, news, and so on. Which in turn makes it possible to transfer application from project to project.

N
newpy, 2016-11-21
@newpy

I'll try to give a slightly different example: a project is a site, and applications are parts of the site, thematically and most importantly logically separated. For example, a blog is maintained on the site, let this application be called "blog". The site has a guest book - this is a different application (logically, the guest book does not apply to the blog, right? It will have its own urls, templates, its own models, views, methods, etc. for working with the guest book). There is a store - this is the "store" application, which also, in general, has nothing to do with the blog. But articles from a blog, this is more of a "blog" application model than a separate application. After all, the articles are directly related to the blog, and in no way to the guest book or the store, articles are not written there. You can get access from one application to another, BUT. Do not make apps linked.
The idea is that you can take your "blog" application and use it in any other project of yours Make a startproject, copy the blog application there, and it should work. Conditionally without rewriting anything "as is" (as is). In one project, several applications generally do not interact in any way. For the Blog there will be a URL leading and working with the blog, for the Store the same way, and for the Guest. The main page can be stored in the Landing application for example or main. The API can also be implemented on the site/project. This is a completely different logic, so this is also a separate application. To understand, ask yourself a question, for example, from the examples I have given, Products|Products is what and to which of the above applies? Try to give an example of what else on the project / site can be separated into a separate application.
UPD.
a97cba340f664f4ea0b52974dbb0a6b0.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question