# django-json-messages
Add json encoded messages (from Django messages framework) to templates
# Install
```sh
pip install django-json-messages
```
# Usage
## Django messages
Make sure the [Django messages framework](https://docs.djangoproject.com/en/1.7/ref/contrib/messages/) is installed and working.
## App
Add `json_messages` to your list of `INSTALLED_APPS`
## Context processor
Add `json_messages.context_processors.json_messages` in your `CONTEXT_PROCESSORS` settings.
A `json_messages` property is now available on the context.
It is a dict version of the messages with `msg` and `type` keys
## Template tags
### Loading
Use `{% load json_messages %}` at the top of your template
### Json dump
Use `{% json_messages_dump %}` to simply dump the json encoded messages into your template
**Note** that all messages' `msg` properties are passed through Django's [escapejs](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#escapejs) for security reasons.
### Script
Use `{% json_messages_script %}` to dump the messages array into a Javascript window variable called ` messages `
This is equivalent to writing
```
<script type="text/javascript">
window.messages = {% json_messages_dump %};
</script>
```
#### Configuration
- Set a context variable `js_variable` to override the name of the window variable use by `{% json_messages_script %}`
*Example:*
```
{% json_messages_script js_variable="blop" %}
```
results in
```
<script type="text/javascript">
window.blop = [{"type":"danger", "msg":"Something"}];
</script>
```
Defaults to *"messages"*
## Package dependencies
None
Add json encoded messages (from Django messages framework) to templates
# Install
```sh
pip install django-json-messages
```
# Usage
## Django messages
Make sure the [Django messages framework](https://docs.djangoproject.com/en/1.7/ref/contrib/messages/) is installed and working.
## App
Add `json_messages` to your list of `INSTALLED_APPS`
## Context processor
Add `json_messages.context_processors.json_messages` in your `CONTEXT_PROCESSORS` settings.
A `json_messages` property is now available on the context.
It is a dict version of the messages with `msg` and `type` keys
## Template tags
### Loading
Use `{% load json_messages %}` at the top of your template
### Json dump
Use `{% json_messages_dump %}` to simply dump the json encoded messages into your template
**Note** that all messages' `msg` properties are passed through Django's [escapejs](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#escapejs) for security reasons.
### Script
Use `{% json_messages_script %}` to dump the messages array into a Javascript window variable called ` messages `
This is equivalent to writing
```
<script type="text/javascript">
window.messages = {% json_messages_dump %};
</script>
```
#### Configuration
- Set a context variable `js_variable` to override the name of the window variable use by `{% json_messages_script %}`
*Example:*
```
{% json_messages_script js_variable="blop" %}
```
results in
```
<script type="text/javascript">
window.blop = [{"type":"danger", "msg":"Something"}];
</script>
```
Defaults to *"messages"*
## Package dependencies
None
Release files for django-json-messages 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-json-messages-0.1.2.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_json_messages-0.1.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 8.9 kB
Release files / django-json-messages-0.1.2.tar.gz
| Download URL | django-json-messages-0.1.2.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90cc703ccd58589a446181e57cb236ba3d87bf03ae543d43b8959e635fd543db
|
|
BLAKE2b-256 checksum How to use checksums |
54eb25e0e2ad02ed6a75852a65e52050e193c58584366de696c7d25fe3dd2904
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_json_messages-0.1.2-py2.py3-none-any.whl
| Download URL | django_json_messages-0.1.2-py2.py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
cc2ab79cf54d99898193951d6aa8f94acbcbc0ef1d49b0320cbafc933b5da844
|
|
BLAKE2b-256 checksum How to use checksums |
64292df2d0543e06b09b5fdbfe52ffa890e44de26a7c4167da3367187ff81162
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |