25đ
Django actually has 3 concepts here:
-
Project (I think this is what youâre calling site): This is the directory that contains all the apps. They share a common runtime invocation and can refer to each other.
-
App: This is a set of views, models, and templates. Apps are often designed so they can be plugged into another project.
-
Site: You can designate different behaviour for an app based on the site (ie: URL) being visited. This way, the same âAppâ can customize itself based on whether or not the user has visited âStackOverflow.comâ or âRackOverflow.comâ (or whatever the IT-targeted version will be called), even though itâs the same codebase thatâs handling the request.
How you arrange these is really up to your project. In a complicated case, you might do:
Project: StackOverflowProject
App: Web Version
Site: StackOverflow.com
Site: RackOverflow.com
App: XML API Version
Site: StackOverflow.com
Site: RackOverflow.com
Common non-app settings, libraries, auth, etc
Or, for a simpler project that wants to leverage an open-source plugin:
Project: StackOverflowProject
App: Stackoverflow
(No specific use of the sites feature... it's just one site)
App: Plug-in TinyMCE editor with image upload
(No specific use of the sites feature)
Aside from the fact that there needs to be a Project, and at least one app, the arrangement is very flexible; you can adapt however suits best to help abstract and manage the complexity (or simplicity) of your deployment.
8đ
From the Django documentation:
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 Web site. A project can contain multiple apps. An app can be in multiple projects.
From this link:
Projects versus applications
This is really more of a separate (though related) question, but understanding the distinction Django draws between a âprojectâ and an âapplicationâ is a big part of good code layout. Roughly speaking, this is what the two terms mean:
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 inidividual applications.
Views, custom manipulators, custom context processors and most other things Django lets you create can all be defined either at the level of the project or of the application, and where you do that should depend on whatâs most effective for you; in general, though, theyâre best placed inside an application (this increases their portability across projects).
- [Django]-How to call a static methods on a django model class during a south migration
- [Django]-ImportError: Could not import settings
- [Django]-Django composite unique on multiple model fields
2đ
The answer to would you have a project with a single app called StackOverflow is an unequivocal no. A site like this might have 20+ apps.
See James Bennettâs âDjangoCon 2008: Reusable Appsâ video presentation which explains this nicely.
- [Django]-Django TemplateSyntaxError â 'staticfiles' is not a registered tag library
- [Django]-Django Manager Chaining
- [Django]-How can I get Django to print the debug information to the console?
0đ
As you said, youâd have a site called StackOverflow with an auth app, questions app, etc.
You should have a look at the Pinax project to see how they lay things out. Itâs one of the better ways to do it since it will increase the modularity and portability of your apps.
- [Django]-Is it OK to use multiple inheritance with Django abstract models?
- [Django]-Should I avoid multi-table (concrete) inheritance in Django by any means?
- [Django]-Django on IronPython