django-switchtemplatedir

Django middleware - symply switch template dir


License
MIT
Install
pip install django-switchtemplatedir==0.0.1

Documentation

django-switchtemplatedir

Django middleware - symply switch template dir

Setup

    git pull https://github.com/haykhman/django-switchtemplatedir.git

In settings.py

Add 'APP_DIR.TemplateDirManager.TemplateDirMiddleware'

Add TEMPLATE_DIR_METHOD string 'switch' or 'subdomain'.

Add TEMPLATE_DIR_SETTINGS dictionary as defoult key named 'default' with value dict with first value string direction of the folder

If need change file format then set value-dict second fild '.format'

Example

    TEMPLATE_DIR_METHOD = 'switch'
    TEMPLATE_DIR_SETTINGS = {'default' : [''], 'd' :  ['desktop/'], 'm' : ['mobile/', '.html']}

In this example we use switch method.

Key 'defoult' reach to root folder, 'd' reach to ROOT/desktop folder, 'm' reach to ROOT/mobile and change predetermined in template_name file format to html

Usage

switch

Recomended to use SwitchTemplateDir method. Import this method from APP_DIR.switcher

In urls add

'.../<str:key>' 

path and switch with key name of TEMPLATE_DIR_SETTINGS

Example

    urls.py
    from APP_DIR.switcher import SwitchTemplateDir
    urlpatterns += [ path('somedir/<str:key>', SwitchTemplateDir.as_view()), ]

example url for example settings is /somedir/d for switch to 'desktop/' folder

Or use switchTemplateDir function from TemplateDirManager and give argument one of TEMPLATE_DIR_SETTINGS keys


Tested on Django 2.0

MIT License