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


Download files

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

Source Distribution

django-switchtemplatedir-0.0.1.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

django_switchtemplatedir-0.0.1-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page