timonweb / django-vue-helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django Vue Helper

  1. Install vue_helper from Pypi: pip install django-vue-helper

  2. Add vue_helper to INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    ...
    'vue_helper'
]
  1. Set the following parameters in your config:
VUE_DEV_MODE = DEBUG
VUE_APP_NAME = 'frontend'
VUE_APP_DIST_DIR_NAME = 'frontend/dist'
VUE_DEV_SERVER_URL = 'http://localhost:8080'
  1. In your Django project create a new app frontend, this is where you will host Vue static assets:
python manage.py startapp frontend
  1. Add frontend app to INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
    ...
    'vue_helper',
    'frontend'
]
  1. Create (or modify) base.html to have a structure similar to:
{% load vue_helper_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  {% vue_preload_styles %}
  {% vue_preload_scripts %}
  {% vue_styles %}
  {% vue_scripts %}
</head>
<body>
  <div id="app">
    <!-- All content here is accessible by Vue app -->
  </div>
</body>
</html>
  1. Make sure you have Vue CLI installed globally in your system, try to run:
vue --version

If you get an error output, that means you need to install Vue CLI, run the following command in terminal:

npm install -g @vue/cli
  1. After installing Vue CLI go into frontend app directory in your project and run the following command:
vue create static_src

This will install a basic vue project into frontend/static_src directory

  1. Go into frontend/static_src, add a vue.config.js file with the following contents:
module.exports = {
  outputDir: "../static/frontend/dist",
  runtimeCompiler: true,
  devServer: {
    public: "http://localhost:8080"
  }
};
  1. Run npm run serve and you should see a vue server starting.

  2. Restart your Django server.

About

License:MIT License


Languages

Language:Python 65.6%Language:Vue 19.6%Language:HTML 12.1%Language:JavaScript 2.7%