I'm trying to make django & Vue work together even though they share the same {{ X }} template syntax.
I know that from django 1.5 we can use the {% verbatim %}
tag. So I thought I could use django templates as usual and in the section where I need VUE to take over I would just use the {% verbatim %} tag. However instead of loading my vue data django loads the {{ variable }}
.
For example my django code looks something like this:
{% verbatim %}
<div id='sessions'>
<h2>{{message}}</h2>
</div>
{% endverbatim %}
And in my app.js file I have:
var sessions = new Vue({
el: '#sessions',
data: {
message: 'Hello Vue!'
}
})
But instead of rendering Hello Vue!
it renders {{message}}
The console doesn't show any error and vue loads correctly otherwise.
How I can make the two work together? Ideally without the need to change the vue.js {{}} syntax.
Django was created in the fall of 2003, when the web programmers at the Lawrence Journal-World newspaper, Adrian Holovaty and Simon Willison, began using Python to build applications. Jacob Kaplan-Moss was hired early in Django's development shortly before Simon Willison's internship ended.
Django is the most popular Python web framework. But Django is also not the simplest technology to learn. It can take a long time before beginners are absolutely comfortable working with Django. However, it's important to have a good understanding of Python before diving into Django.
High-level: When to use DjangoIf you can check even a few of the statements below (without strongly disagreeing with any), chances are that Django is good for your project. You need to develop a web app or API backend. You need to move fast, deploy fast, and also make changes as you move ahead.
You can change Vue's interpolation delimiters to whatever you want.
var sessions = new Vue({
el: '#sessions',
delimiters: ['${', '}'],
data: {
message: 'Hello Vue!'
}
})
That way you can use whatever your framework needs.
Edit
It turned out in this case, @Costantin had more than one div#sessions on the page.
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