Solution to tag conflicts between Django and angular. js templates

Source: Internet
Author: User
Tags django server

Reference: 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/

This {} label conflict problem, in the latest version of Django 1.5 Proposed the template built-in solution verbatim label: https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#verbatim content in this label can avoid being parsed by the server-side template. If you are using version 1.4 or earlier, you can use the system built-in tag templatetag to output special strings, or use the following scheme to write less characters. We made a special customization. For the solution for client template configuration, refer to the above reference article.

Refer to the one in the first article and use the server tag to output the tag solution required by the client, because the template contains texts such as {"}"}, the output is encapsulated into Django.

Contains tags, and the output of the Rear Double braces also uses a variable. Otherwise, the output is ambiguous. Let's talk about the Code:

# Coding: UTF-8 ''' created on @ Author: hulda ''' from Django import templateregister = template. library () @ register. inclusion_tag ('dlb. djhtml ') def DLB (): ''' double left brace: double left braces, it is mainly used to solve the conflict between the template tag of the Django server side and the template tag of the angularjs client. ''' return {}@ register. inclusion_tag ('drb. djhtml ') def DRB (): ''' double right brace: Double right braces, it is mainly used to solve the conflict between the template tag of the Django server side and the template tag of the angularjs client. ''' return {"DRB ":"}}"}

Source code of DLB. djhtml:

{{'{{'}}

Source code of DRB. djhtml:

{{drb}}

Conclusion: Frankly speaking, this server-side solution may have a slight performance defect compared to client settings, but when the web site has performance problems, the team's optimization capability is probably not a problem.

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.