Django1.10 Configuring JINJA2 Templates

Source: Internet
Author: User
Tags configuration settings

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.