Todo App | Django REST Framework & Ajax

Dennis Ivy · 111K views · 2020 · 55:14

Open on YouTube

Web developmentPython, Ruby & scripting languagestutorial

Why Stack Overflow recommends it

Stack Overflow users link it as a worked example of pairing Django REST Framework with a JavaScript front end for async calls, and many follow it step by step before asking about errors.

Recommended by 1 people across 1 different months, 2020 to 2022.

What it is

A 55-minute tutorial by Dennis Ivy that builds a to-do app front end in vanilla JavaScript, calling a Django REST Framework API built in an earlier video. It covers fetching, creating, updating and deleting tasks through Ajax requests, with source code on GitHub.

What people said

Recommends cshelly · 2021-07 · Stack Overflow · on “Perform action from a form or link without refreshing the page/view with django”

You cannot do this using only django, since django is by nature synchronous ( in layman's language it means that whenever you want to send/fetch data from the server your webpage will reload). So, you need to use asynchronous technologies like AJAX [LINK] . One way to accomplish what you are trying to do is by building a restful API service only for registration ( using django rest framework [LINK] ). Then you can use Ajax to make asynchronous calls to your rest API. You can checkout this really nice tutorial video by Dennis Ivy for more details on implementation [this video] . PS: Ideally people use a frontend framework like React to make all API calls and they make a separate backend using drf,

Cites IbbyR · 2020-04 · Stack Overflow · on “Cross-Origin Request Blocked Django-project”

I've built a REST API and I'm following along with this tutorial: [this video] I've completed all up until 13minutes. addition of a JS script into the html template. When I run and check the console I get: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at [LINK] . (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)." I have no idea what part of my projects the CORS header goes into? <script type="text/javascript"> buildList() function buildList(){ var wrapper = document.getElementById('list-wrapper') var url = ' [LINK] ' fetch(url) .then((resp) => resp.json()) .then(function(data){ console.log('Data:', data) }) } </script>

Cites goku10 · 2021-04 · Stack Overflow · on “Django Flashing/Flickering on each Render on CRUD function”

At first, I have removed $("#incompleteTodo").html("") from the main.js file. Then, Created let todo_incomplete = []; outside the function for storing the data locally and add ed let todoItems = data.results; for (let todo in todoItems) { try { document.getElementById(`todo_${todo}`).remove(); } catch(err){} } After the loop ends, I have added if(todo_incomplete.length > todoItems.length){ for (var i = todoItems.length; i < todo_incomplete.length; i++){ document.getElementById(`todo_${i}`).remove(); } } todo_incomplete = todoItems; I used this method and it's working fine. I haven't found any solutions for this. On implementing the same method for completed_Items I was able to achieve on bot

Cites Smokar · 2022-11 · Stack Overflow · on “My API is sending data but its not getting stored in the backend”

So i was following this tutorial [this video] , with different approach of mine ( instead of being a to do app, I'm trying to make it a clinic management system ). So the problem I'm facing is that my api is receiving data, and there is no errors plus I'm getting 200 status code from the local server which means everything is okay, but its not hence the data isn't being stored in the DB for some reason. this is the code: models.py class Employee(models.Model): fullname = models.CharField(max_length = 250) age = models.DateField(null=True, blank=True) gender = models.CharField(max_length=10, choices=(('Male', 'Male'), ('Female', 'Female')), default='Male') usertype = models.CharField(max_length =