Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Django middleware - symply switch template dir

Project description


Django middleware - symply switch template dir


    pip install django-switchtemplatedir


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'


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


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


Recomended to use SwitchTemplateDir method. Import this method from django-switchtemplatedir.switcher

In add


path and switch with key name of TEMPLATE_DIR_SETTINGS

    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

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
Filename, size django-switchtemplatedir-0.0.1.tar.gz (2.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page