django-ajax-toolkit

Ajax goodies for Django projects
Download

django-ajax-toolkit Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Eleni Lixourioti
  • Publisher web site:
  • https://github.com/Geekfish/

django-ajax-toolkit Tags


django-ajax-toolkit Description

django-ajax-toolkit is a Django app that provides Ajax goodies for Django projects.Returning JSON in viewsJsonResponseIf you want to extend your views to work with ajax you may choose to return json data in your response. To make this easier you can use JsonResponse found in ajaxtoolkit.http:from ajaxtoolkit.http import JsonResponseclass MyView(TemplateView): def get(self, request, *args, **kwargs): if request.is_ajax: context = self.get_context_data() return JsonResponse(context) # ...This will set the correct mimetype (application/json) and serialise your context data into a json object.Ajax MiddlewareIf you're using Django's messages framework, you can also add ajaxtoolkit.middleware.AjaxMiddleware in your middleware.This will inject all messages generated in your request into your JsonResponse object:from django.contrib import messagesfrom ajaxtoolkit.http import JsonResponseclass MyView(TemplateView): def get(self, request, *args, **kwargs): if request.is_ajax: context = self.get_context_data() messages.info(request, "This is very useful") messages.warning(request, "Be careful!") return JsonResponse(context) # ...This would be rendered as the following:{ //... 'django_messages': }Product's homepage


django-ajax-toolkit Related Software