diff options
| author | Tim Graham <timograham@gmail.com> | 2013-02-07 05:51:25 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-02-07 07:05:36 -0500 |
| commit | aa85ccf8ce11c4b8374c74fd9dfe72647be49ada (patch) | |
| tree | 4e68ef43ea9f82b93b23acf5267e35c18c2c6fce /docs/intro/reusable-apps.txt | |
| parent | 43efefae692729925c0f75c55e93bd1f33f42bfd (diff) | |
Fixed #19706 - Tweaks to the tutorial.
Thanks Daniele Procida.
Diffstat (limited to 'docs/intro/reusable-apps.txt')
| -rw-r--r-- | docs/intro/reusable-apps.txt | 72 |
1 files changed, 11 insertions, 61 deletions
diff --git a/docs/intro/reusable-apps.txt b/docs/intro/reusable-apps.txt index 99fb62e4d7..dcccd583c0 100644 --- a/docs/intro/reusable-apps.txt +++ b/docs/intro/reusable-apps.txt @@ -50,8 +50,8 @@ projects and ready to publish for others to install and use. Python package easy for others to install. It can be a little confusing, we know. -Completing your reusable app -============================ +Your project and your reusable app +================================== After the previous tutorials, our project should look like this:: @@ -67,78 +67,28 @@ After the previous tutorials, our project should look like this:: admin.py models.py tests.py - urls.py - views.py - -You also have a directory somewhere called ``mytemplates`` which you created in -:doc:`Tutorial 2 </intro/tutorial02>`. You specified its location in the -TEMPLATE_DIRS setting. This directory should look like this:: - - mytemplates/ - admin/ - base_site.html - polls/ - detail.html - index.html - results.html - -The polls app is already a Python package, thanks to the ``polls/__init__.py`` -file. That's a great start, but we can't just pick up this package and drop it -into a new project. The polls templates are currently stored in the -project-wide ``mytemplates`` directory. To make the app self-contained, it -should also contain the necessary templates. - -Inside the ``polls`` app, create a new ``templates`` directory. Now move the -``polls`` template directory from ``mytemplates`` into the new -``templates``. Your project should now look like this:: - - mysite/ - manage.py - mysite/ - __init__.py - settings.py - urls.py - wsgi.py - polls/ - admin.py - __init__.py - models.py templates/ polls/ detail.html index.html results.html - tests.py urls.py views.py + mytemplates/ + admin/ + base_site.html -Your project-wide templates directory should now look like this:: - - mytemplates/ - admin/ - base_site.html - -Looking good! Now would be a good time to confirm that your polls application -still works correctly. How does Django know how to find the new location of -the polls templates even though we didn't modify :setting:`TEMPLATE_DIRS`? -Django has a :setting:`TEMPLATE_LOADERS` setting which contains a list -of callables that know how to import templates from various sources. One of -the defaults is :class:`django.template.loaders.app_directories.Loader` which -looks for a "templates" subdirectory in each of the :setting:`INSTALLED_APPS`. +You created ``mysite/mytemplates`` in :doc:`Tutorial 2 </intro/tutorial02>`, +and ``polls/templates`` in :doc:`Tutorial 3 </intro/tutorial03>`. Now perhaps +it is clearer why we chose to have separate template directories for the +project and application: everything that is part of the polls application is in +``polls``. It makes the application self-contained and easier to drop into a +new project. The ``polls`` directory could now be copied into a new Django project and immediately reused. It's not quite ready to be published though. For that, we need to package the app to make it easy for others to install. -.. admonition:: Why nested? - - Why create a ``polls`` directory under ``templates`` when we're - already inside the polls app? This directory is needed to avoid conflicts in - Django's ``app_directories`` template loader. For example, if two - apps had a template called ``base.html``, without the extra directory it - wouldn't be possible to distinguish between the two. It's a good convention - to use the name of your app for this directory. - .. _installing-reusable-apps-prerequisites: Installing some prerequisites |
