DEV Community

Maxime Guilbert
Maxime Guilbert

Posted on • Edited on

5 2

Combine Flask and Vue.js

If you want to expose an HTML page using **Flask* and Vue.js (without webpack), you need to set up something to let Vue.js know where it can work.*


Flask uses Jinja a templating language to display information in a webpage. And, like Vue.js, their delimiters are

{{ ... }}
Enter fullscreen mode Exit fullscreen mode

Examples

A Jinja example

<title>{% block title %}{% endblock %}</title>
<ul>
{% for user in users %}
  <li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>
Enter fullscreen mode Exit fullscreen mode

A Vue.js example

<div id="app">
  {{ message }}
</div>
Enter fullscreen mode Exit fullscreen mode

So, how to make them live together?


Solution

In Vue.js, you can change the delimiter of your components!

var app = new Vue({
    el: '#app',
    delimiters: ['[[', ']]'],
    data: {
      message: 'Hello Vue!'
    }
  })
Enter fullscreen mode Exit fullscreen mode
<div id="app">
  [[ message ]]
</div>
Enter fullscreen mode Exit fullscreen mode

With that, Vue.js and Jinja can live together and you can display Vue.js pages with Flask. 👍

Alt Text


Links


I hope it will help you! 😀

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

DEV works best when you're signed in—unlocking a more customized experience with features like dark mode and personalized reading settings!

Okay