by dtjones · 6y ago · 0 comments
"When you google for Django + Vue, most results will be focused on using Django for your backend and Vue for a separate frontend project."
There are times when this makes sense, but there are times when you just need to sprinkle a but of Vue magic onto part of your site, without turning the whole thing into an SPA.
- easy to answer questions whilst watching the video
- quick to navigate to a specific question
- video visible at all times
- short+long summary of each answer visible when answering a specific question
- long description of question visible
- can be operated using mouse or keyboard (on laptop/desktop) or touch (tablet)
The rest of the site was regular Django, with a bit of jQuery here and there. I settled on:
- a regular Django form, with a single field to accept the a json string of the actual answers (the questions might change in future)
- a description of all the questions, descriptions, choices stored in a Django model, and sent to the page as json
- Vue rendering part of the page (the bit with the category selectors, question text, choices, descriptions)
Vue helped me deliver a pretty slick UI and didn't add any technical debt. (Not saying I didn't add any technical debt overall, just that the front-end part didn't contribute.)
I was commenting more generally on the approach to building a web app with Django and including external js libraries in Django templates, which I've done in the past as project requirements have changed over time. After including external js libraries to Django templates, there is a lot less support in terms of resources and supporting libraries such as testing frameworks. If the client-side project is initialized with Vue, the project can benefit from the overwhelming amount of supporting resources.
You can also get live reloading working.