<p>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.</p>

<p>Does anyone have examples, suggestions, and <em>explanations</em> 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.</p>

[{'answer_id': 44152, 'author': 'rcreswick', 'author_id': 3446, 'author_profile': 'https://Stackoverflow.com/users/3446', 'pm_score': 3, 'selected': False, 'text': '<p>This page does a good job of addressing some of my questions: <a href="http://www.b-list.org/weblog/2006/sep/10/django-tips-laying-out-application/" rel="nofollow noreferrer">http://www.b-list.org/weblog/2006/sep/10/django-tips-laying-out-application/</a></p>\n\n<p>Specifically: </p>\n\n<blockquote>\n  <ol>\n  <li>To define custom template tags or filters, you must create a sub-directory in the application’s directory called templatetags, and it must contain a file named __init__.py so that it can be imported as a Python module.</li>\n  <li>To define unit tests which will automatically be noticed by Django’s testing framework, put them in a module called tests (which can be either a file named tests.py or a directory called tests). The testing framework will also find any doctests in that module, but the preferred place for those is, of course, the docstrings of the classes or functions they’re designed to test.</li>\n  <li>To provide custom SQL which will be executed immediately after your application is installed, create a sub-directory called sql inside the application’s directory; the file names should be the same as the names of the models whose tables they’ll operate on; for example, if you have an app named weblog containing a model named Entry, then the file sql/entry.sql inside the app’s directory can be used to modify or insert data into the entries table as soon as it’s been created. </li>\n  </ol>\n</blockquote>\n\n<p>The note about tests.py and tests (the directory) also holds for models, which helps address the problem of having way to many tests (or models) for one file.</p>\n\n<p>I would still like to see some examples / suggestions for app/project break down, and  big django sites that work well.</p>\n'}, {'answer_id': 135468, 'author': 'Carl Meyer', 'author_id': 3207, 'author_profile': 'https://Stackoverflow.com/users/3207', 'pm_score': 5, 'selected': True, 'text': '<p>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.</p>\n\n<p>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 <a href="http://pinaxproject.com" rel="noreferrer">Pinax</a> is probably the closest we have to a standard).</p>\n\n<p>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 <a href="http://docs.djangoproject.com/en/dev/topics/i18n/#topics-i18n" rel="noreferrer">docs</a>.</p>\n'}, {'answer_id': 252237, 'author': 'bwinton', 'author_id': 735, 'author_profile': 'https://Stackoverflow.com/users/735', 'pm_score': 2, 'selected': False, 'text': '<p>The <a href="http://pinaxproject.com/" rel="nofollow noreferrer">Pinax project</a> is built around the idea of small reusable apps, which are easily brought together into a project.  They\'ve used the project <a href="http://cloud27.com/" rel="nofollow noreferrer">Cloud 27</a> as a demo project.</p>\n\n<p>The Django project I\'m working on (called Basie.  It\'s pre-0.1, so no link yet.) is trying to follow the Pinax model, and so far it\'s working out fairly well.</p>\n'}, {'answer_id': 427643, 'author': 'Alf', 'author_id': 11682, 'author_profile': 'https://Stackoverflow.com/users/11682', 'pm_score': 1, 'selected': False, 'text': "<p>My current layout stems from me wanting to have a test-version of my sites.  This means having two projects for every site, since they need different configurations, and forces me to move all the applications out of the projects.</p>\n\n<p>I've created two folders: $APP_ROOT/devel and $APP_ROOT/prod.  These contain all the apps.  Using source control (in my case git) I have the apps in devel at the HEAD revision, while the apps in prod are locked to the PROD tag.  The templates also have their own folder with the same layout as the apps.</p>\n\n<p>Now I'm able to do all my development in the devel-apps folder and the matching template-folder.  When I have something I'm happy with, I tag that revision and update prod.</p>\n"}, {'answer_id': 2687645, 'author': 'number5', 'author_id': 29489, 'author_profile': 'https://Stackoverflow.com/users/29489', 'pm_score': 3, 'selected': False, 'text': '<p>I found Zachary\'s layout quite useful\n<a href="http://zacharyvoase.com/2010/02/03/django-project-conventions/" rel="nofollow noreferrer">Zachary Voase’s Blog » Django Project Conventions, Revisited.</a>  </p>\n'}, {'answer_id': 11592273, 'author': 'Adam Hammouda', 'author_id': 1542656, 'author_profile': 'https://Stackoverflow.com/users/1542656', 'pm_score': 1, 'selected': False, 'text': '<p>I really like <a href="http://www.deploydjango.com/django_project_structure/index.html" rel="nofollow">Randall Degges\'</a> post on this subject.  He leaves out info on how to glue the settings files together, but I\'ll have a post on that I\'ll be able to link, but for now anyone can check out <a href="https://github.com/ahammouda3/personal-page" rel="nofollow">my repo</a> where I include some direction in the readme.</p>\n'}]
['https://Stackoverflow.com/questions/44135', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3446/']