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>
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pointofvue-0.0.3.tar.gz.
File metadata
- Download URL: pointofvue-0.0.3.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e19b06498d57331cea15dc8d3a506e826b4a15bcb457d3ec3ff8edd8e55f6216
|
|
| MD5 |
42e7fc3fc9dde5526af3153d35dde7ef
|
|
| BLAKE2b-256 |
1ca6b48497d697e7c05c7ec7ffbff737edd20d1d8eb85fd210f6475a59927a0f
|
File details
Details for the file pointofvue-0.0.3-py3-none-any.whl.
File metadata
- Download URL: pointofvue-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
557cf702b267326058378c29ad69947dd33fed333b345c8c5feebb3c754a54c7
|
|
| MD5 |
f4a101f52e89c091b135cebfdf32edb9
|
|
| BLAKE2b-256 |
edfbf1bbfa6355cb015461d1350c7817fabb6e4164f5dfd40843150518b00853
|