Loader¶
Loader is in charge to resolve page item options and to create UrlPattern objects from a given page registry.
Basically you could use it like this:
staticpages_loader = StaticpagesLoader()
staticpages_loader.build_urls()
This will return you a list of UrlPattern objects, note than without any argument
the loader will use the settings for default values from settings and especially
the setting STATICPAGES.
In the following sample, you can see a more concrete way that will build
UrlPattern objects directly mounted as urls, something you can use in a Django
urls.py:
staticpages_loader = StaticpagesLoader()
urlpatterns = [
...
# Add pages urls using the same template
*staticpages_loader.build_urls([
"index",
"foo",
"bar",
])
]
That will respectively configure pages on urls /, /foo/ and /bar/.
- class staticpages.loader.StaticpagesLoader(template_basepath=None, name_base=None, url_basepath=None, view_class=None)[source]¶
A
TemplateViewinheriter with some more attributes to implement staticpages features.- Keyword Arguments:
template_basepath (string) – Path to prefix a page template path. If empty, default value comes from
STATICPAGES_DEFAULT_TEMPLATEPATHsetting.name_base (string) – Name to prefix a page url name. If empty, default value comes from
STATICPAGES_DEFAULT_NAME_BASEsetting.url_basepath (string) – Base url path to prefix a page url path. If empty, default value comes from
STATICPAGES_DEFAULT_URLPATHsetting.view_class (object) – A Class based view to use instead of the default
staticpages.views.StaticPageViewthat is an extend of Django class base viewTemplateView. Given class must respect expected attributestemplate_name,page_optionsandstaticpages.
- validate_item(data)[source]¶
Validate item data is correct.
- Parameters:
data (dict) – Item options to validate. See
resolve_itemfor expected data.
- resolve_item(data)[source]¶
Resolve a registry item.
Expected data may be something like:
{ "path": "foo/", "re_path": r"foo/$", "template": "foo", "template_path": "foo.html", "name": "foo", "extra": "anything anykind", }
See Option specifications for more details.
- Parameters:
data (dict) – Item options.
Returns – dict: A dictionnary of resolved options. See Template context variables for more details.
- resolve_registry(registry=None)[source]¶
From given registry, resolve each registry item to a tuple suitable to build urls.
- Keyword Arguments:
registry (list) – List of either string or dict. Dictionnary is the verbose way to define options opposed to a String which is expected to be a template name (without leading path and ending HTML suffix) that will be used to resolve options. If this argument is empty, default value will comes from
STATICPAGESsetting.- Returns:
A list of item options as dictionnary.
- Return type:
list