Ways to resolve Django and angular.js template tag conflicts

Source: Internet
Author: User
Tags django server

Reference article: http://yanhua365.lofter.com/post/b417f_1f0361

Http://stackoverflow.com/questions/8302928/angularjs-with-django-conflicting-template-tags

http://blog.boxelderweb.com/2012/11/16/providing-django-template-variables-as-constants-to-angularjs/

In front of that, the current version of the Django template has a verbatim ¶ tag, is the right way to do this thing.

This {{}} tag conflict issue, in the latest version of Django 1.5 presented a template built-in solution verbatim tags: https://docs.djangoproject.com/en/1.5/ref/templates/ builtins/#verbatim The contents of this tag can be avoided by the server-side template parsing. Using the 1.4 and previous versions of the students can consider using the system built-in label Templatetag output special strings, or with the following scheme, is to write fewer characters. Special custom-made a bit. As for the client template configuration solution, look at the above reference article.

Mainly refer to the first article in the middle, with the server-side tag to output the client's desired label solution, because the template is everywhere {{"}}"}} Such text is easy to confuse, so the output is packaged into Django

The included label resolves, where the output of the double curly braces is also used as a variable, otherwise the output is ambiguous. Needless to say, on the code:

#Coding:utf-8" ""Created on 2013-7-9 @author: Hulda" "   fromDjangoImportTemplate Register=template. Library () @register. Inclusion_tag ('dlb.djhtml')  defDLB ():" "' Double left brace: Two open curly braces, mainly to resolve the problem of the Django server-side template label and the Angularjs Client template label conflict" "      return{} @register. Inclusion_tag ('drb.djhtml')  defDRB ():" "' Double right brace: Two closing curly braces, mainly to resolve the problem of the Django server-side template label and the Angularjs Client template label conflict" "            return{"DRB":"}}"}

Summary: Frankly, this kind of server-side solution, compared to the client settings may be slightly less performance, but the Web site in the performance of the problem, the team optimization capability estimation should not be a problem.

How to troubleshoot Django and angular.js template label conflicts

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.