• Stars
    star
    1,495
  • Rank 31,403 (Top 0.7 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Django Rest + Vue JS Template

Django Vue Template ✌️ 🐍

Vue Logo Django Logo

This template is a minimal example for an application using Vue and Django.

Vue and Django are clearly separated in this project. Vue, Yarn and Webpack handles all frontend logic and bundling assessments. Django and Django REST framework to manage Data Models, Web API and serve static files.

While it's possible to add endpoints to serve django-rendered html responses, the intention is to use Django primarily for the backend, and have view rendering and routing and handled by Vue + Vue Router as a Single Page Application (SPA).

Out of the box, Django will serve the application entry point (index.html + bundled assets) at / , data at /api/, and static files at /static/. Django admin panel is also available at /admin/ and can be extended as needed.

The application templates from Vue CLI create and Django createproject are kept as close as possible to their original state, except where a different configuration is needed for better integration of the two frameworks.

Alternatives

If this setup is not what you are looking for, you might want look at other similar projects:

Prefer Flask? Checkout my gtalarico/flask-vuejs-template

Demo

Live Demo

Includes

  • Django
  • Django REST framework
  • Django Whitenoise, CDN Ready
  • Vue CLI 3
  • Vue Router
  • Vuex
  • Gunicorn
  • Configuration for Heroku Deployment

Template Structure

Location Content
/backend Django Project & Backend Config
/backend/api Django App (/api)
/src Vue App .
/src/main.js JS Application Entry Point
/public/index.html Html Application Entry Point (/)
/public/static Static Assets
/dist/ Bundled Assets Output (generated at yarn build)

Prerequisites

Before getting started you should have the following installed and running:

Setup Template

$ git clone https://github.com/gtalarico/django-vue-template
$ cd django-vue-template

Setup

$ yarn install
$ pipenv install --dev && pipenv shell
$ python manage.py migrate

Running Development Servers

$ python manage.py runserver

From another tab in the same directory:

$ yarn serve

The Vue application will be served from localhost:8080 and the Django API and static files will be served from localhost:8000.

The dual dev server setup allows you to take advantage of webpack's development server with hot module replacement. Proxy config in vue.config.js is used to route the requests back to django's API on port 8000.

If you would rather run a single dev server, you can run Django's development server only on :8000, and you have to build the Vue app first and the page will not reload on changes.

$ yarn build
$ python manage.py runserver

Pycharm additional configuration

Follow this guide to ensure you have pipenv setup

https://www.jetbrains.com/help/pycharm/pipenv.html

Click "Edit Configurations"

Select Django Server under templates

Click + to create a config from the templates

In Environment variables add

PYTHONUNBUFFERED=1;DJANGO_SETTINGS_MODULE=backend.settings.dev

Click Apply then Ok

Deploy

Heroku Server

$ heroku apps:create django-vue-template-demo
$ heroku git:remote --app django-vue-template-demo
$ heroku buildpacks:add --index 1 heroku/nodejs
$ heroku buildpacks:add --index 2 heroku/python
$ heroku addons:create heroku-postgresql:hobby-dev
$ heroku config:set DJANGO_SETTINGS_MODULE=backend.settings.prod
$ heroku config:set DJANGO_SECRET_KEY='...(your django SECRET_KEY value)...'

$ git push heroku

Heroku's nodejs buildpack will handle install for all the dependencies from the package.json file. It will then trigger the postinstall command which calls yarn build. This will create the bundled dist folder which will be served by whitenoise.

The python buildpack will detect the Pipfile and install all the python dependencies.

The Procfile will run Django migrations and then launch Django'S app using gunicorn, as recommended by heroku.

Heroku One Click Deploy

Deploy

Static Assets

See settings.dev and vue.config.js for notes on static assets strategy.

This template implements the approach suggested by Whitenoise Django. For more details see WhiteNoise Documentation

It uses Django Whitenoise to serve all static files and Vue bundled files at /static/. While it might seem inefficient, the issue is immediately solved by adding a CDN with Cloudfront or similar. Use vue.config.js > baseUrl option to set point all your assets to the CDN, and then set your CDN's origin back to your domains /static url.

Whitenoise will serve static files to your CDN once, but then those assets are cached and served directly by the CDN.

This allows for an extremely simple setup without the need for a separate static server.

Cloudfront Setup Wiki

More Repositories

1

flask-vuejs-template

Flask + Vue JS Template
Python
1,324
star
2

pyairtable

Python Api Client for Airtable
Python
706
star
3

ironpython-stubs

Autocomplete stubs for common IronPython/.NET libraries
Python
248
star
4

revitpythonwrapper

Python Wrapper for the Revit API
Python
134
star
5

pipenv-pipes

A PipEnv Environment Switcher
Python
133
star
6

revitapidocs.code

Python Scripts fo Repository for RevitAPIdocs.com
Python
96
star
7

aec-startups

List of AEC Startups
Vue
57
star
8

python-revit-resources

List of Resources for Python-Revit Lovers
53
star
9

pyrevitplus

PyRevitPlus - Extensions for PyRevit
Python
50
star
10

vue-threejs-rhino-demo

Rhino 3dm Three Js viewer
JavaScript
46
star
11

revitapidocs

Online Revit API Documentation: 2015, 2016, 2017, 2017.1, 2018
31
star
12

interactive-elastic-analyzer

Interactive Elasticsearch Analyzer
HTML
12
star
13

revit-api-chms

A Repository of .chm (Windows Help Files) from the Revit API Sdk
10
star
14

apidocs.samples

Samples for ApiDocs.co
C#
8
star
15

au2017

AU 2017 Python for Dynamo Presentation
Python
5
star
16

python-algorithms

Python Algorithms
Python
5
star
17

pm

A Tiny CLI utility to help you navigate your project directories, written in Go
Go
5
star
18

gtalarico

Gui Talarico's Github Profile
Python
4
star
19

pigeonpy

Flask Server with Angular Front End to Access Forge API
JavaScript
4
star
20

foldify

Helper tool to manage directories and directory templates.
Python
3
star
21

au-2019-web-apis

Vue
3
star
22

python-project

My personal template for bootstraping new python projects
Shell
3
star
23

project_sandwich

Python
2
star
24

locker

A virtual locker simulator
Python
2
star
25

win-bootstrap

Boostraping scripts for setting up my Windows Machines
PowerShell
2
star
26

dynotify

Notification System for Posts in the Dynamo Community Forum
Python
1
star
27

gtalarico.com

Personal Website
HTML
1
star
28

markdown.is

Vue
1
star