Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve double curly brackets issue when using Vue + Django template language?

I am using Django template language and would like to use Vue on my project. One main problem I encountered is {{...}} syntax. My Vue data is not rendered at all.

<div id="app">{{ message }} // This is just empty on my page </div>

And I am just using this basic Vue script:

var app = new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue!'
  }
})

How do I solve this?

like image 697
ivanasetiawan Avatar asked Sep 03 '17 15:09

ivanasetiawan


People also ask

What are double curly braces in Django?

- Values surrounded by double curly braces at the start and end represent output for variables. Variables are passed by Django views, url options or context processors into templates.

What does double curly braces mean in Python?

Template Values {}The double curly brackets are not HTML but scripting code. The term inside, interest, is a placeholder, sort of like the name and address in a form letter. The string {{interest}} will be replaced when the HTML template is converted into straight HTML that is sent over the network to the user.


2 Answers

What glenfant said is easy, but this is even easier.

var app = new Vue({
    delimiters: ['{', '}'],
    el: '#app',
    data: { message: 'Hello Vue!' },
})

That’s all: you configure Vue with the tag it should use to work. :) I use just one brace – {…} – but you can use doubled square brackets, too: [[ and ]].

like image 144
Miguel Avatar answered Sep 30 '22 16:09

Miguel


Use the verbatim template tag. https://docs.djangoproject.com/en/1.11/ref/templates/builtins/#verbatim

<div id="app">{% verbatim %}{{ message }}{% endverbatim %}</div>
like image 21
glenfant Avatar answered Sep 30 '22 18:09

glenfant