Skip to main content

A simple, opinionated way to incorporate VueJS into Django apps

Project description

PointOfVue

A simple, opinionated way to incorporate VueJS into your Django applications

Installation

pip install PointOfVue

Add pointofvue to your Django installed apps:

INSTALLED_APPS = [
    # other apps ...
    'pointofvue',
]

Basic Usage

In your view, import pointofvue and send a pointofvue.VueContext instance to your template

import pointofvue

def view_handler(request):
    vue_ctx = pointofvue.VueContext()
    vue_ctx.set_data('var1', 'My value')

    return render(request, 'template.html', {
        "vue_ctx": vue_ctx,
    })

In your template, write your Vue code in a #app element and use ${ and } for accessing Vue data. Then load the pointofvue templates and call the {% vue %} tag with your VueContext to load VueJS and create an app.

<div id='app'>
    The value of 'var1' is <b>${ var1 }</b>
</div>

{% load pointofvue %}
{% vue vue_ctx %}

Custom JavaScript

It is likely that you won't be able to get away with just writing HTML Vue alone, you may need to define methods and other JS native entities in custom JavaScript.

Note: pointofvue encourages you to not write inline JavaScript in your Django HTML templates. Write separate JS files and serve them via staticfiles instead

Define a Vue entry point that exports your Vue data. It may look like this:

import MyCustomComponent from './my-component.js';

const components = {
    MyCustomComponent,
};

export {
    components,
};

Build that JS file (target as a library if using vue-cli-service). Then register your script with the Python VueContext in your view:

vue_ctx.add_script('myscript')

Now you can use your custom component in your template:

<div id="app">
    <b>My Custom Component</b>
    <MyCustomComponent />
</div>

Development

Releasing

I use bump2version to manage version bumping. This will update the version number in the library, commit it, and create a version tag.

bump2version minor
git push --follow-tags

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pointofvue-0.1.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pointofvue-0.1.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file pointofvue-0.1.1.tar.gz.

File metadata

  • Download URL: pointofvue-0.1.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pointofvue-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ee87bb0154adff32317ac09e8d6700000c9e26127e486506c79e4958bd9d0bfc
MD5 302f0079d1ab7fb5105d961afb4d5531
BLAKE2b-256 7b3ea96e1f6496e74a6c0228dfb4be7713a6c11066eadcaa2c0eca339fddf42a

See more details on using hashes here.

File details

Details for the file pointofvue-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pointofvue-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pointofvue-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9726ce577e56c293dacda3bb1de196b1df22ce6dfe6715caf508faa6ce0c1fd
MD5 408a513a76310f35e0bf215d0f9c133d
BLAKE2b-256 75bffcb3888a19967e1fb0ab67bdebeafde7f4a568de2837d8afe9f58ee6d4c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page