How do you divide your project into applications in Django?

前端 未结 2 1643
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 02:30

I am not really sure how to divide my Django projects into applications.

What things should I consider when laying out a Django project?

相关标签:
2条回答
  • 2020-12-31 03:28

    James Bennett has written a blog entry about this,

    Django tips: laying out an application, section "Projects versus applications":

    An application tries to provide a single, relatively self-contained set of related functions. An application is allowed to define a set of models (though it doesn’t have to) and to define and register custom template tags and filters (though, again, it doesn’t have to).

    A project is a collection of applications, installed into the same database, and all using the same settings file. In a sense, the defining aspect of a project is that it supplies a settings file which specifies the database to use, the applications to install, and other bits of configuration. A project may correspond to a single web site, but doesn’t have to — multiple projects can run on the same site. The project is also responsible for the root URL configuration, though in most cases it’s useful to just have that consist of calls to include which pull in URL configurations from individual applications.

    0 讨论(0)
  • 2020-12-31 03:29

    I can understand why you have such doubt, Django's documentation about the application concept isn't very clear when it comes to how to organize a database / ER model into specific apps.

    Let's say you're building an API using Django and DRF and your ER diagram has many FKs and you're not sure how apps really work. In that case, I suggest you to organize the API code into a single app.

    0 讨论(0)
提交回复
热议问题