forked from orbit-oss/flask
Some documentation improvements
This commit is contained in:
parent
60e143ecb6
commit
77743a5f15
2 changed files with 49 additions and 1 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue