1. Install the JINJA2 module:
Pip Install JINJA2
2, configuration settings:
templates = [ { ' BACKEND ': ' django.template.backends.jinja2.Jinja2 ', ' DIRS ': [ Os.path.join (base_dir, ' templates ')], ' App_dirs ': true, ' OPTIONS ': { ' environment ': ' MirMobAdmin.jinja2.environment ' }, }, { ' backend ': ' django.template.backends.django.DjangoTemplates ', ' DIRS ': [], ' app_dirs ': true, ' OPTIONS ': { ' conText_processors ': [ ' Django.template.context_processors.debug ', ' Django.template.context_processors.request ', ' Django.contrib.auth.context_ Processors.auth ', ' Django.contrib.messages.context_processors.messages ', ], }, },]
3. Create mirmobadmin/jinja2.py file:
#!/usr/bin/python #coding: Utf-8from __future__ import absolute_import # python 2 onlyfrom Django.contrib.staticfiles.storage Import staticfiles_storagefrom django.core.urlresolvers import Reversefrom jinja2 Import environmentdef Environment (**options): env = Environment (**options) env.globals.update ({' Static ': STA Ticfiles_storage.url, ' url ': Reverse,}) return env
The purpose of this file is to add both static and URL template tags to the Jinja2 template
4, the template is replaced by the original {% static ' xxx.js '%} to {{static (' Xxx.js ')}}
The test is now normal!
This article is from the "Operations Notes" blog, make sure to keep this source http://lihuipeng.blog.51cto.com/3064864/1836608
Django1.10 Configuring JINJA2 Templates