I
I
Igor Che2017-03-09 13:09:56
Django
Igor Che, 2017-03-09 13:09:56

How to run vue.js in Django?

Django doesn't work with vue.js. Even a simple Hello world.
view.py:

from django.shortcuts import render
from django.http import HttpResponse
from django.core import serializers
from .models import State

def main(request):
  return render(request, 'inspector/vue.html')

def get_state(request):
  panel_list = State.objects.all()
  data = serializers.serialize('json', panel_list)
  return HttpResponse(data, 'application/javascript')

vue.html
<script src="https://unpkg.com/vue/dist/vue.js"></script>

<div id="app">
  <p>{{ message }}</p>
</div>

<script type="text/javascript">
new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue.js!'
  }
})
</script>

If you open this template directly in the browser as normal html, everything works.
I suspect it's the curly braces {{ }}, Django expects template variables in them.
How to resolve this conflict?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2017-03-09
@chewarer

Change the type of brackets in vue - does he know how to do this?
Django template
https://docs.djangoproject.com/en/dev/ref/template...

Y
Yeldos Adetbekov, 2017-03-09
@dosya97

Add delimiters:[''], to the main body of the application or component. Note that all components are independent.

A
Alexander, 2017-12-14
@rusbaron

Add COMMAND at the end of the dockerfile or copy the entrypoint.sh file with the launch of jenkins itself:
Well, when starting the container with the command to add/bin/bash /usr/local/bin/jenkins.sh

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question