Git Product home page Git Product logo

djajax's Introduction

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);
    })();
}();
</script>

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.

settings.py

DJAJAX_URL_REVERSE_LOOKUPS = [
    'login',
    'www:index',
]

index.html

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

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

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.

djajax's People

Contributors

adamghill avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

inhersight

djajax's Issues

Example Project

Hi Adam. I came here after reading this post (after reading your post about PostGIS/GeoDjango in dev.to). I'd like to know if you can do a very simple example project to see this library working, of course, if you have the time to do it.

Thanks!

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.