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.