Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
3Abstract
4---------
6The apps within a project often require the creation of AJAX views. These may be ad hoc or part of a more organized
7structure. SuperDjango's AJAX app provides a simple interface for registering AJAX views across a project.
9Install
10-------
12Update project settings:
14.. code-block:: python
16 # settings.py
17 INSTALLED_APPS = [
18 # ...
19 "superdjango.interfaces.ajax.apps.AutoConfig",
20 # ...
21 ]
23 # Default module name is ajax.
24 SUPERDJANGO_AJAX_MODULE_NAME = "ajax"
26If you wish to manually manage an AJAX registry, use ``superdjango.ajax.apps.DefaultConfig`` instead.
28Utilize the URLs:
30.. code-block:: python
32 # main/urls.py
33 from superdjango.interfaces.ajax import ajax
35 urlpatterns = [
36 # ...
37 path('ajax/', include(ajax.get_urls())),
38 # ...
39 ]
41Usage
42-----
44Create your AJAX views as normal, utilizing a viewset to capture the views within your app:
46.. code-block:: python
48 # views.py
49 from superdjango.views import GenericView, JSONMixin, ViewSet
51 class SomeAjaxCall(JSONMixin, GenericView):
52 # ...
54 class SomeOtherAjaxCall(JSONMixin, GenericView):
55 # ...
57 class MyAjaxViewSet(ViewSet):
58 views = [
59 SomeAjaxCall,
60 SomeOtherAjaxCall,
61 ]
63 # ajax.py
64 from superdjango.ajax import ajax
65 from .views import MyAjaxViewSet
67 ajax.register("myapp", MyAjaxViewSet)
69You could, of course, home your AJAX views in the ``views.py`` of your app instead of the ``ajax.py``.
71"""
72from django.conf import settings
73from django.utils.module_loading import autodiscover_modules
74from .interfaces import ajax
76__author__ = "Shawn Davis <shawn@superdjango.com>"
77__maintainer__ = "Shawn Davis <shawn@superdjango.com>"
78__version__ = "0.5.0-x"
80__all__ = (
81 "ajax",
82)
84API_MODULE_NAME = getattr(settings, "SUPERDJANGO_AJAX_MODULE_NAME", "ajax")
87def autodiscover():
88 """Automatically find (and load) ``ajax.py`` files located in installed Django apps."""
89 autodiscover_modules(API_MODULE_NAME)
92default_app_config = "superdjango.interfaces.ajax.apps.DefaultConfig"