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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-switchtemplatedir-0.0.1.tar.gz.
File metadata
- Download URL: django-switchtemplatedir-0.0.1.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc2996d78961eeee6539bebb564c6aca1cb97b0fc3efd955f249b1f2ed14f006
|
|
| MD5 |
576293f6805ce4d97cdf8f4f8ac54d7f
|
|
| BLAKE2b-256 |
3ae221df0612fb2889eff10f80737f141c130583afb51bac5125cfcc655b9dbe
|
File details
Details for the file django_switchtemplatedir-0.0.1-py3-none-any.whl.
File metadata
- Download URL: django_switchtemplatedir-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d477016f0482289e4b6d1cd2e58cd9d4cff12873ab04617503b022d4554cc645
|
|
| MD5 |
44629ab572e217e548cb8a6536fa144b
|
|
| BLAKE2b-256 |
ff06cd3b8a68f1d7e8c1daaea23556e8d21b895a93563e4f5caf851d653498ed
|