Skip to main content

Helper utilities for working with Ajax in Django

Project description

# djajax
Some helper utilities for building Ajax applications without throwing out all the nicities of Django out the window (or moving wholesale to something like Django REST Framework).

## Models

### SerializableMixin
A model mixin that gives an easy way to serialize a model or queryset to JSON.

#### to_json
Default dictionary representation of a model that can later be converted to JSON. May be overriden in a model by defining `to_json` in the model.

#### serialize (static method)
Serializes a queryset/model into a JSON-ifable dictionary. Will paginate a queryset if necessary.

## Template tags

### jsonify filter
Outputs a dictionary input a JSON object. Returns an empty obj if the template variable is empty.

<script type="text/javascript">
window.onload = function() {
(function() {
var djajaxJsonData = {{ json|jsonify }};
console.log('djajaxJsonData', djajaxJsonData);

### djajax_urls tag
Outputs a dictionary of reverse lookups to urls for use in Javascript. Urls must be specified in DJAJAX_URL_REVERSE_LOOKUPS and must not need arguments.

<script src="{% static 'js/djajax.js' %}"></script>

<script type="text/javascript">
window.onload = function() {
(function() {
var djajaxUrls = {% djajax_urls %};
console.log('djajaxUrls', djajaxUrls);

## HTTP responses

### JsonHttpResponse
Returns a JSON response with the correct headers set.

## View helpers

### is_idempotent
Returns whether the request is idempotent (changes state on the server) or not.

### response
Returns an appropriate AJAX response for an AJAX request.

### get_from_post_or_get
Attempts to first get a value from the POST query dictionary, and if that fails, to look at the GET querystring.

Project details

Download files

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

Files for djajax, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size djajax-0.0.4-py3-none-any.whl (8.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size djajax-0.0.4.tar.gz (8.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page