Skip to main content

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

MIT License

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-switchtemplatedir, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size django_switchtemplatedir-0.0.1-py3-none-any.whl (4.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size django-switchtemplatedir-0.0.1.tar.gz (2.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page