What is the best way to layout a large django project? The tutorials provide simple instructions for setting up apps, models, and views, but there is less information about how apps and projects should be broken down, how much sharing is allowable/necessary between apps in a typical project (obviously that is largely dependent on the project) and how/where general templates should be kept.
Does anyone have examples, suggestions, and explanations as to why a certain project layout is better than another? I am particularly interested in the incorporation of large numbers of unit tests (2-5x the size of the actual code base) and string externalization / templates.
No. The best thing in django is it's a package, you don't want to install library that supports django. Because it have everything in it. You can easily create static website using django.
Django comes with six built-in apps that we can examine.
Django might help in some specific use-cases, but it might not be wise to develop everything with Django (or any other framework alone). You need to build a very basic app, which does not require database, file operations, or anything even remotely complex. Micro frameworks are better suited for these use-cases.
The major guidelines are similar to any other large code project. Apps should address a single, clearly-defined responsibility. The name "application" is a misnomer; Django apps should be thought of more as reusable components which can be plugged together to create a real application. Tests for each app should be contained within that app. Apps should be decoupled from each other as much as possible, but clearly there will be dependencies, so the goal should be to keep the dependency graph as simple and sane as possible.
I prefer to keep all the templates for a project under a single project-wide templates directory, with a subdirectory for each app (using a template subdirectory for each app is a very strong convention in Django, as it avoids template name collisions between apps). The reason for a single project-wide templates directory is that templates, template inheritance trees, and block names can be quite project-specific, so it's hard to provide "default" app templates that can plug in to any project. There have been some attempts to settle on standard naming conventions for base site-wide templates and the blocks they define, but I haven't seen a standard emerge yet (the way they do things over at Pinax is probably the closest we have to a standard).
Re "string externalization", if you mean i18n and l10n, Django has strong support for that and standard places where it puts the .po files - check the docs.
I found Zachary's layout quite useful Zachary Voase’s Blog » Django Project Conventions, Revisited.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With