71👍
I highly recommend jQuery. There are several tutorials on how to implement it.
http://lethain.com/entry/2007/dec/11/two-faced-django-part-5-jquery-ajax/
http://lethain.com/entry/2007/dec/01/using-jquery-django-autocomplete-fields/
http://vincentxu.net/minimal-ajax-in-django-with-jquery-post
NOTE: Microsoft also announced a while ago that jQuery would be the official client-side framework for ASP.NET MVC, so its good to know regardless of what server side framework you’re using.
62👍
I think this may be what you’re looking for: django-dajax
Pretty well documented. Simple api. Very clean and nice. I plan on using it more in some of my projects. It’s JS library agnostic, and works well with jQuery if that’s your thing.
UPDATE:
Other solutions similar to dajaxice, but not standard dajax.
- https://github.com/joestump/django-ajax – Joe Stump’s solution that makes it dead simple to create restful endpoints from your models.
- https://bitbucket.org/jespern/django-piston/wiki/Home – Similar idea, but a bit more robust. You can define the data format for your endpoints (xml vs json etc).
- https://github.com/toastdriven/django-tastypie – Similar to piston, but I’ve had better luck with tastypie.
In the end they mostly work the same.
- Define/include some predefined URL routes.
- Register models/views/functions that will be used as data sources.
- Enjoy.
UDATE2:
This advice is super old. Should probably research other solutions.
- [Django]-Django filter queryset __in for *every* item in list
- [Django]-How can one use enums as a choice field in a Django model?
- [Django]-Removing 'Sites' from Django admin page
16👍
There’s nothing about Django that makes any of the libraries easier or work better with the framework. Just use the one that fits your brain the best.
Having said that, my sense is that jQuery is more popular in the Django world and is what I personally use. Most notably, many of the apps in Pinax require jQuery. Some other shared apps and code snippets for Django:
http://www.djangosnippets.org/tags/jquery/
http://code.google.com/p/django-ajax-validation/
http://code.google.com/p/django-todo/
http://code.google.com/p/donita/
- [Django]-Can't compare naive and aware datetime.now() <= challenge.datetime_end
- [Django]-Django, Models & Forms: replace "This field is required" message
- [Django]-Redirect to named url pattern directly from urls.py in django?
8👍
Also keep in mind that the newest Django books (Python Web Development with Django, Learning Website Dev with Django) use jQuery in their tutorials.
- [Django]-Django Rest Framework custom response message
- [Django]-CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False
- [Django]-Getting the SQL from a Django QuerySet
7👍
Checkout Dajax:
Dajax Project
Easy to use AJAX libraries for Django
Fast, easy and lightweight libraries
to implement AJAX inside your django
projects. Ready to use in 5 minutes.Dajax is a powerful tool to easily and
super-fastly develop asynchronous
presentation logic in web applications
using python and almost no lines of JS
source code.It supports up to four of the most
popular JS frameworks: Prototype,
jQuery, Dojo and mootols.
- [Django]-Mixin common fields between serializers in Django Rest Framework
- [Django]-Count() vs len() on a Django QuerySet
- [Django]-How to spread django unit tests over multiple files?
4👍
I’ve successfully used jquery, YUI and Dojo on different django projects. There’s nothing about any of those that made it better to use with django specifically. I agree with jpartogy that mochikit may fit django more than any other just because of the “pythonic” (twisted-like) API. It really depends on what you are looking for in an ajax framework.
Personally I like what jQuery can do with given amounts of code but the greatest challenge in writing jQuery code is making it readable.
YUI is much more verbose than other frameworks because it sets a convention for using namespaces, but there are shortcuts to write less code and it avoids trying to make javascript look like something else.
Dojo tries to make javascript look like Java and from my experience is pretty slow. It has some nice widgets and a javascript implementation of the django templating language (which is pretty useful even outside of django projects).
I personally avoid prototype and mootools because they can break other javascript code (or vice versa).
If you are new to javascript and ajax I’d recommend jQuery because it’s the easiest to start with. But I don’t expect any js framework to be integrated with django mostly because there’s really no need for that.
- [Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter
- [Django]-Elegant setup of Python logging in Django
- [Django]-What is the difference between cached_property in Django vs. Python's functools?
2👍
+1 to Soviut and Daniel for good answers. Jquery is a nice framework. Besides Pinax a couple other “big” Django applications use it: Satchmo and Review Board (which switched from another framework… mootools IIRC).
Also popular is rolling your own Javascript without using any framework, for example the Django admin.
The only other suggestion I might make is that, if you are a very experienced Pythonhead, then you might like mochikit which comes under some criticism for being too ‘pythonic’.
It seems to be the framework of choice for Turbogears but I personally haven’t seen any Django projects using it.
- [Django]-How to use 'select_related' with get_object_or_404?
- [Django]-How to debug Django commands in PyCharm
- [Django]-Django: manage.py does not print stack trace for errors
1👍
Okay this might be subjective because the definition of ‘best’ can mean different to each individual. But since you are working with Django, that means you will get your hands down with Python syntax. One notable Javascript library that doesn’t get exposed too much is Mochikit. The good thing about it is it has syntax that is familiar to Python programmer (because the creator is a Python programmer). It has quite nicely written down documentation as well. TurboGears out-of-the-box supports Mochikit.
- [Django]-Iterating over related objects in Django: loop over query set or use one-liner select_related (or prefetch_related)
- [Django]-Django order_by query set, ascending and descending
- [Django]-Change a field in a Django REST Framework ModelSerializer based on the request type?
1👍
If you need to work with AJAX in your django projects with very little setup and simple to use, my offer is:
Fast, flexible and easy to use AJAX libraries for django projects. Contains ajax decorator, ajax middleware, shortcuts and more.
- [Django]-Django: Get an object form the DB, or 'None' if nothing matches
- [Django]-Django: Grab a set of objects from ID list (and sort by timestamp)
- [Django]-Django – Annotate multiple fields from a Subquery
0👍
The phrase “Best AJAX Library” is highly subjective and depends on personal preferences, existing know how, requirements of the work etc. etc.
While I prefer jQuery for (almost) everything, I know some people whio swear by Dojo or ExtJS. There might be case where you want to use jQuery but requirements might be dictate that you use ExtJS.
All said. Use jQuery. jQuery rocks 😉
- [Django]-How to write setup.py to include a Git repository as a dependency
- [Django]-Filtering dropdown values in django admin
- [Django]-Token Authentication for RESTful API: should the token be periodically changed?
0👍
Django doesn’t really tie in with the client side. Use whatever you’re comfortable with. Django plays well with everything in that area, because you just write it in the templates.
- [Django]-Django: How to check if the user left all fields blank (or to initial values)?
- [Django]-Unittest Django: Mock external API, what is proper way?
- [Django]-Multiple Models in a single django ModelForm?