Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gtalarico committed Aug 10, 2018
1 parent 187a7f3 commit 206cd58
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,40 @@
![Vue Logo](/src/assets/logo-vue.png "Vue Logo")
![Django Logo](/src/assets/logo-django.png "Django Logo")

This template is a minimal example for structuring a VueJs + Django Rest Framework.
This template is a minimal example for structuring an application using VueJs and Django (RestFramework).

The goal is to let Vue + Vue Cli handle the frontend and asset bundling,
and use Django + Rest Framework to manage a Rest API + Data Models.
and use Django + Rest Framework to manage a Data Models, API, and Static files.

Vue Cli and Django Project template are kept as close as possible to their
original state, with the exception of some configuration that is critical
to the integration of the two frameworks.

### Demo

https://django-vue-template-demo.herokuapp.com/
[Live Demo](https://django-vue-template-demo.herokuapp.com/)

### Includes

* Django
* Django Restframework
* Django Whitenoise
* Gunicorn
* Vue Cli 3
* Vue Router
* Configuration for Heroku Deployment


## Prerequisites

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

- [X] Yarn - [instructions](https://yarnpkg.com/en/docs/install#mac-stable)
- [X] Vue Cli 3 - [instructions](https://cli.vuejs.org/guide/installation.html)
- [X] Python 3
- [X] Pipenv

## Setup Template Locally
## Setup Template

```
$ git clone https://www.github.com/gtalarico/django-vue
Expand All @@ -52,26 +63,28 @@ $ yarn serve
```

The Vuejs template will be served from `localhost:8080` and the Django Api
will be served form `localhost:8000`.
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 reload.
webpack's development server with hot module replacement.
Proxy config in `vue.config.js` is used to router the requests
back to django's Api.

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

```
$ yarn build
$ python manage.py runserver
```



## Deploy

* Set `ALLOWED_HOSTS` on `project.settings.production.py`

A Heroku deploymnet is preconfigured:
### Heroku Server

```
$ heroku apps:create django-vue-template-demo
Expand All @@ -87,20 +100,18 @@ $ git push heroku

## Static Assets

See `settings.prod` and `vue.config.js` for comments on static assets strategy.

This template is configured for development, but not a lot is needed to have a decent
production setup.

The strategy we take is to use Django Whitenoise to serve all static files at `/static/`.
See `settings.prod` and `vue.config.js` for notes on static assets strategy.

This may seem inefficient for a production server, but that's immediately solved
by adding a CDN.
Create CDN distribution with Cloudfront or similar, configure the `vue.config.js` `baseUrl` options to set your point to the CDN, and set your CDN's origin back to your domains `/static` url.
This template implements the approach suggested by Whitenoise Django.
For more details see [WhiteNoise Documentation](http://whitenoise.evans.io/en/stable/django.html)

The CDN will fetch assets, cache, and then distribute it for you.
This allows for a extremely simple setup without the need to keep a separate static server or
upload static assets.
It uses 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.

For more details see [WhiteNoise Docs](http://whitenoise.evans.io/en/stable/django.html)
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.

0 comments on commit 206cd58

Please sign in to comment.