Django middleware - symply switch template dir
Project description
django-switchtemplatedir
Django middleware - symply switch template dir
Setup
pip install django-switchtemplatedir
In settings.py
Add 'django-switchtemplatedir.TemplateDirManager.TemplateDirMiddleware'
Add TEMPLATE_DIR_METHOD 'switch' or 'subdomain'
Add TEMPLATE_DIR_SETTINGS dictionary as defoult key named 'default' and list type value. Set first index of the list direction to the folder.
Optional - if need change the files format, set second index of the list '.format'
Example
TEMPLATE_DIR_METHOD = 'switch'
TEMPLATE_DIR_SETTINGS = {'default' : [''], 'd' : ['desktop/'], 'm' : ['mobile/', '.html']}
Explanation
In this example we use switch method
Key 'defoult' reach to template root folder, 'd' reach to ROOT/desktop folder, 'm' reach to ROOT/mobile and change predetermined in template_name file format to html
switch
Recomended to use SwitchTemplateDir method. Import this method from django-switchtemplatedir.switcher
In urls.py add
'SOME_DIR/<str:key>'
path and switch with key name of TEMPLATE_DIR_SETTINGS
Example
urls.py
from django-switchtemplatedir.switcher import SwitchTemplateDir
urlpatterns += [ path('somedir/<str:key>', SwitchTemplateDir.as_view()), ]
If set up by example below, then link /somedir/d will switch to 'desktop/' folder
Or use switchTemplateDir function from TemplateDirManager and give argument one of TEMPLATE_DIR_SETTINGS keys
Tested on Django 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-switchtemplatedir-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc2996d78961eeee6539bebb564c6aca1cb97b0fc3efd955f249b1f2ed14f006 |
|
MD5 | 576293f6805ce4d97cdf8f4f8ac54d7f |
|
BLAKE2b-256 | 3ae221df0612fb2889eff10f80737f141c130583afb51bac5125cfcc655b9dbe |
Hashes for django_switchtemplatedir-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d477016f0482289e4b6d1cd2e58cd9d4cff12873ab04617503b022d4554cc645 |
|
MD5 | 44629ab572e217e548cb8a6536fa144b |
|
BLAKE2b-256 | ff06cd3b8a68f1d7e8c1daaea23556e8d21b895a93563e4f5caf851d653498ed |