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?
- 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.
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.
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 ]]
.
Use the verbatim
template tag. https://docs.djangoproject.com/en/1.11/ref/templates/builtins/#verbatim
<div id="app">{% verbatim %}{{ message }}{% endverbatim %}</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With