Websites can process AJAX requests, including ones that are built with Python and Django.
Since you are a WordPress-centric developer, making the leap from WordPress/PHP over to Python will be challenging. However, let's see if we can get you started.
jQuery or JavaScript's AJAX handling doesn't care what language or framework/app/library is running on the server side. It packages up the dataset, configures what it wants back, and then sends it to an endpoint on the server.
What you need to do on the server side then is handling:
- Routing
- Validation
- Request processing
- Returning back a serialized packet
Disclaimer: It appears you are speaking about non-RESTful WordPress implementation. Therefore, I'll make the comparisons using that approach.
WordPress handles the routing for you. You point your request to the endpoint of the admin URL. Then you register your processing callback to the event name wp_ajax_{your-action}
. The action is defined in the AJAX packet you sent to the server. Next, you do your validation with a nonce check. Then you run your code to process the request, build any HTML, pass it through a JSON serializer, and send it back to the browser.
Let's relate WordPress over to Django for you:
Routing - Endpoint
In Django, you need to declare the endpoint so that it knows who to do the routing. Then you can use that endpoint in your AJAX request. It's an extra step that you don't do in WordPress.
Validation
WordPress uses nonce. Django you will use csrf_token
.
Processing
You write you code in Python that handles the processing for the request. WordPress you write in PHP.
Send it Back
Django provides you with JSON, XML, and YAML serializers. You'll likely use JSON. This will package it up for the return. Then you can send it back.
Some Tutorials to Help
You won't find any that will convert WordPress' implementation over to Python or Django. Instead, you'll want to learn about AJAX first to ensure you understand how it works and what is required. Then you can set off to architect a test in Django.
Here are some tutorials to help you: