GithubHelp home page GithubHelp logo

brleinad / django-vue-hybrid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raisins/django-vue-hybrid

2.0 1.0 2.0 1.54 MB

Use Django, Vue and Vite together

JavaScript 0.10% Dockerfile 0.03% Python 0.31% HTML 0.19% Vue 0.02% CSS 99.36%
django python vue vuejs vite

django-vue-hybrid's Introduction

Django Vue Hybrid (with vite)

screenshot of Vue running on top of Django

This repo is intended as a proof-of-concept/base project for a hybrid Django/Vue app. This approach is fairly opinionated and based on experimentation by raisins.

Aside from the Vue integration, this is a standard dockerized Django 3/PostgreSQL project.

The common app within django_web consists of one TemplateView with some extra context for demonstration purposes.

Vue is managed by vue-cli, which is installed globally within the container.

Node modules and commands are managed by Yarn.

Django and Vue are linked by django-webpack-loader and webpack-bundle-tracker. See the common/index.html template for use of the {% render_bundle %} tag.

This project also uses tailwindcss as a PostCSS plugin, along with plugins for css imports and nested rules. Tailwind is managed through the postcss-cli.

The vue.config.js file does several important things:

  • configures devServer to use the port defined in docker-compose.yml
  • handles publicPath/outputDir options for serve/build on dev/production
  • alters the Webpack configuration to not generate html files or handle preloading or prefetching output files, as these are handled by Django and webpack-loader
  • defines how to chunk files

Project Setup

  • Install Docker
  • Clone or fork the project
  • cp django_web/.env_example django_web/.env
  • docker-compose up
  • Go into djangovue_web container docker exec -it django_vue_web bash
  • In the docker container now run: yarn install and then yarn serve
  • As configured via docker-compose.yml, the project will be running at localhost:8000/

Development

Check out scripts defined in package.json

  • yarn serve will compile tailwindcss and start both Django's dev server and vue-cli's dev server, configured for hot reloading
  • Python packages are managed with Poetry. To use the Poetry cli within the container, you must first source $HOME/.poetry/env.

Demo

Look at the following files to see a demo of Django and Vue playing together.

  • django_web/apps/core/views.py defining a simple template view with some extra context
  • django_web/apps/core/templates/demo.html passing the Django context to the Vue component as a prop
  • django_web/vue/components/DemoComponent.vue a simple Vue component using Tailwindcss
  • django_web/vue/main.js lazy loading the Vue component so it can be used in the Django template

django-vue-hybrid's People

Contributors

brleinad avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.