Browse Source

Some documentation improvements

pull/112/head
Armin Ronacher 15 years ago
parent
commit
77743a5f15
  1. 46
      docs/patterns/packages.rst
  2. 4
      flask/module.py

46
docs/patterns/packages.rst

@ -197,3 +197,49 @@ did in the example above, or we just use the function name::
@frontend.route('/')
def index():
return "I'm the index"
.. _modules-and-resources:
Modules and Resources
---------------------
.. versionadded:: 0.5
If a module is located inside an actual Python package it may contain
static files and templates. Imagine you have an application like this::
/yourapplication
__init__.py
/apps
/frontend
__init__.py
views.py
/static
style.css
/templates
index.html
about.html
...
/admin
__init__.py
views.py
/static
style.css
/templates
list_items.html
show_item.html
...
The static folders automatically become exposed as URLs. For example if
the `admin` module is exported with an URL prefix of ``/admin`` you can
access the style css from its static folder by going to
``/admin/static/style.css``. The URL endpoint for the static files of the
admin would be ``'admin.static'``, similar to how you refer to the regular
static folder of the whole application as ``'static'``.
If you want to refer to the templates you just have to prefix it with the
name of the module. So for the admin it would be
``render_template('admin/list_items.html')`` and so on. It is not
possible to refer to templates without the prefixed modlue name. This is
explicit unlike URL rules.

4
flask/module.py

@ -90,7 +90,9 @@ class Module(_PackageBoundObject):
:ref:`working-with-modules` section.
.. versionadded:: 0.5
The `static_path` parameter was added.
The `static_path` parameter was added and it's now possible for
modules to refer to their own templates and static files. See
:ref:`modules-and-resources` for more information.
:param import_name: the name of the Python package or module
implementing this :class:`Module`.

Loading…
Cancel
Save