Тёмный

Todo App | Django REST Framework & Ajax 

Dennis Ivy
Подписаться 214 тыс.
Просмотров 106 тыс.
50% 1

Check out my Complete Django course! dub.sh/NvGboTI
Creating a To-Do app with the Django REST Framework. We will use the API we build out in the previous video to handle the front end with vanilla JavaScript.
Follow me on Twitter: / dennisivy11
You can find the video to the backend build out in the link here: • Django Rest Framework ...
Source code + Live Demo: github.com/div...

Опубликовано:

 

19 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 157   
@DennisIvy
@DennisIvy 2 месяца назад
Don't forget to check out my Complete Django course! dub.sh/NvGboTI
@imsKo
@imsKo 4 года назад
I want to thanks you for the amazing tutorial. Thanks to you, I was able to have a better understanding on how to attach both Django and JS together which I didn't know before. Also, for those who wish to understand the problem that occurs at 30:35. I believe the reason the event listeners aren't working is because the wrapper.innerHTML is creating a whole new string each time it iterates through the for loop. When you create a whole new string, you lose the reference to all the previous event listeners that you have added because wrapper.innerHTML has been rewritten entirely again (it created an entire new string). A good example to compare would be creating a variable inside a for loop and the variable overwriting itself on each for loop. Now, as to why only the last button ends working, it's because on the last iteration of the for loop. You apply an 'addEventListener' to the last index [i] of wrapper.innerHTML and there isn't another iteration afterwards that would overwrite wrapper.innerHTML. To avoid creating a new string on each iteration (which can slow down the performance if a string gets too big and it has to copy itself over and over again). I learned the method 'insertAdjancentHTML' doesn't create a whole new string through each iteration, instead it injects (or inserts) the new html directly into the original html which is like 100 times faster. The solution at 31:12 would be to replace: wrapper.innerHTML += item to wrapper.insertAdjacentHTML('beforeend', item) Like below: var list = data for (var i in list) { var item = ` ${list[i].title} Edit - ` wrapper.insertAdjacentHTML('beforeend', item) // Inside the element, insert after its last child. var editBtn = document.getElementsByClassName('edit')[i]; editBtn.addEventListener('click', function() { editItem() })
@jees__antony
@jees__antony 4 года назад
thanks, this seems less lines of code and insertAdjacentHTML document states that it is more faster in operation
@munteanionut3993
@munteanionut3993 2 года назад
Thanks a lot for the explanation! Won my upvote, kind sir. Nonetheless, any idea why JavaScript behaves like this? You mention "wrapper.innerHTML is creating a whole new string each time it iterates through the for loop:... but that line of code (ie: "wrapper.innerHTML += item") is using the '+=' operator... so shouldn't it be equivalent to "wrapper.innerHTML = wrapper.innerHTML + item" -> meaning that you first get the initial (previous) value and then add something to it? Thus one SHOULD NOT lose the reference to the variable? (ie: the reference to everything that you built so far & stored in the variable...) - this behavior is kinda unintuitive... but I feel I might be losing some fundamentals of JS..
@imsKo
@imsKo 2 года назад
@@munteanionut3993 No problem! It has to do with how innerHTML treats values as a string and strings in javascript are immutable. What this means is that each time you try to edit a string in js, it has to create a whole new object to store the new value. Since now you have a whole new object with your new data, all previous references are lost and the garbage collector will be clearing those variables from memory since they are now unreachable. Simple code example: // Initializes text with a new string object. var text = ""; for (randomText in listOfText) { // Each loop, the variable text is getting assigned a new string object // because strings in js are immutable and therefore to edit its content // it has to create a new object to accommodate with its new changes. // // Therefore, each time we make any edits to the variable text, a new string object is created // and the previous object reference of text is no longer accessible (since the variable is getting overwritten by a new object) // and now the js garbage collector is free to clear that data from memory since is unreachable. text += randomText ; } Hope this explanation is helpful!
@munteanionut3993
@munteanionut3993 2 года назад
@@imsKo yes, it is! Thank you!
@AngelTorres89
@AngelTorres89 Год назад
Thank you, this works perfectly
@scarletlady9870
@scarletlady9870 Год назад
The year is 2023, and the javascript error with editbtn and the for loop, has been moderated. Now the original code works fine now. `for(let i in list){let editbtn = document.getElementsByClassName('edit')[i] editBtn.addEventListener('click', function(){ editItem(list[i]); }` works fine now in Javascript. Big fan of your videos Dennis! Much love from Nigeria
@abhisheknautiyal7956
@abhisheknautiyal7956 4 года назад
I can't thank you enough for the quality content you make. These videos definitively deserve a lot more views and likes. You just got a subscriber. Cheers mate.
@ryan_0337
@ryan_0337 4 года назад
I liked the video before I watch it. Thanks for your consistency and regularity Dennis
@DennisIvy
@DennisIvy 4 года назад
I appreciate you Ryan! Thanks for your support :)
@atumasaake5510
@atumasaake5510 3 года назад
I like his videos before watching them too. I am assured of the quality. Thank you Dennis
@norbertmarko6479
@norbertmarko6479 4 года назад
Your videos are mad good, you somehow always upload what I need, and after watching your explanations I can always start to work off of them.
@themax734
@themax734 4 года назад
This was so cool. I didn't know much at all about webdev going into this, but it was still easy to follow and now I feel like I'll be able to use the django rest framework for the backend of my android app
@TheAremoh
@TheAremoh 4 года назад
What a way to say good morning to me. Thank you Denis
@DennisIvy
@DennisIvy 4 года назад
Hope you like this one :)
@TheAremoh
@TheAremoh 4 года назад
@@DennisIvy Always
@chaitanyaasati
@chaitanyaasati 3 года назад
Thank you for creating same project in Django without Rest Framework, Django with Rest Framework and React+Django. It helped a lot.
@abhinavjha9231
@abhinavjha9231 3 года назад
what is the use of making rest framework in the backend if we can do all the CRUD operation from django-admin panel. Are both different? please reply to me .
@sangeethsubramoniam3094
@sangeethsubramoniam3094 3 года назад
This is a comment made by the creator. just re sharing. hope it answers ! That's a very practical question :) You technically don't need to use REST but its a common practice today because lots of websites use frameworks such as React and Angular or just use Javascript to render data. This is common because of AJAX lets us make our websites more dynamic and allows us to load/re-render data without reloading the page each time. A perfect example would be when we add or delete an item. Because of our API we are able to make a call to the database and re-render our list without ever needing to reload the page. Hope that makes sense :)
@Arbadjie
@Arbadjie 4 года назад
Am loving this. I am gonna start implementing javaScript and react to my channel. Thanks, Dennis
@NLesly
@NLesly 2 года назад
Waaooooooo! I admit that this is one of the best videos I have ever watched. Thanks very much Dennis Ivy Look forward to watch that of React
@nitishbhardwaj9603
@nitishbhardwaj9603 2 года назад
Thank you so much @Dannis for this session, I just now completed this, growing my skills from here...
@realdaly
@realdaly 2 года назад
I love how u try to fix the problems and keep going with the tutorial
@kennedywee
@kennedywee 3 года назад
Dennis Ivy, I wanted to tell you that you are doing amazing work with your tutorial! Tell me if you got any blogs or your own tutorial website! Can't get enough of your brilliant contents. Keep the good work! Thank you very much
@SreebashDasFitness
@SreebashDasFitness 4 года назад
Awesome content! Thank you so much dear. Please build more content.
@khongthefork
@khongthefork 4 года назад
At 53:45, instead of writing out a for loop just for 1 element, you can just remove the last extra element with document.getElementById(`data-row-${list_snapshot.length - 1}`).remove();
@vicky3333ful
@vicky3333ful 3 года назад
Thank you for this amazing tutorial, I have a better understanding of DRF now. There is an alternative solution for CSRF token that is: let csrftoken = document.querySelector('input[name="csrfmiddlewaretoken"]').value; then send this to the fetch header.
@japsimransingh9933
@japsimransingh9933 3 года назад
Love your django tuts You just explain it perfectly.
@hiusho
@hiusho 3 года назад
Thank you for understable and compact lesson!
@qubitwave6953
@qubitwave6953 4 года назад
Simple to follow and love for all your training series. After following the edit event handler from you, I came up with the following idea for the delete buttons. //Adding event handler for all delete buttons buildList for loop let deleteCollection = Array.from( document.getElementsByClassName("delete") ); for (let i = 0; i < deleteCollection.length; i++) { deleteCollection[i].addEventListener("click", deleteItem); } //Delete Method function deleteItem(e) { e.preventDefault(); let url = `${baseURL}task-delete/${e.target.dataset.id}`; fetch(url, { method: "DELETE", headers: { "Content-type": "application/json", "X-CSRFToken": csrftoken } }).then(response => { document .getElementById("list-wrapper") .removeChild(e.target.parentElement.parentElement); }); }
@BohdanDuCiel
@BohdanDuCiel 3 года назад
I had another idea on the editItem part: put an inline onclick function and pass the current item id as a parameter.
@anopta
@anopta 2 года назад
Hi Dennis. That was explosive. Thanks very much. I have a quick question. Why did you use POST method for Update instead of a PUT method? I am just curious.
@solomonbestz
@solomonbestz 10 месяцев назад
I am curious too, though I made mine function with the PUT method, don't want story in the future 😅😅
@tomcat9761
@tomcat9761 6 месяцев назад
i think he just made a mistake or forgot it.
@DeepakRajan
@DeepakRajan 4 года назад
I'm new to javascript! Is ajax is also covered in the video? I think only REST framework is covered. Or am I not understanding it properly?
@alexanderfox429
@alexanderfox429 3 года назад
If anybody is having issues with No 'Access-Control-Allow-Origin' you have to install some middle-ware to fix it. Go here and follow the instructions: dzone.com/articles/how-to-fix-django-cors-error
@munteanionut3993
@munteanionut3993 2 года назад
thanks a lot! worked like a charm! you should be higher in the comments list : D
@realdaly
@realdaly Год назад
Your comment saved me, thank you so much^^
@elonmusk2142
@elonmusk2142 4 года назад
Денис ты крутой чувак , даже лучше чем Хауди Хо
@snelledre
@snelledre 4 года назад
Dennis, I learn a lot from you but i have a question. For only an webapp (no mobile) is then only Django a good idee or advise you also to use django rest framework with react or Vue. And why should you use react over vue?
@DennisIvy
@DennisIvy 4 года назад
That's a good question. Django REST framework can be used for several reasons. 1. You want to build a mobile app or use something like React or Vue to render templates. Or maybe you just want to render via vanilla JS 2. You want to provide your data to others in JSON format and want to give them the ability to work with it. These are just a few reasons but ultimately if you just want to build a webapp and don't have a clear reason to use react or view then you do NOT need Django REST framework. To my understanding Vue is more light weight and easier to understand than react but I don't know enough to have a preference :)
@irinsajan2870
@irinsajan2870 2 года назад
Something that I really wanted! You are doing a great job :) Thank you for this content.
@sathyanarayanan99
@sathyanarayanan99 3 года назад
At 31:00, you're creating a variable within a loop. If you do that the variable you've created would be deleted or overwritten in the next iteration. So each time the loop was looping, the variable was getting overwritten like second was overwritting first, third overwritting second ... sixth overwritting fifth and that's why you were left with the last one. Instead you could've created the variable outside the for loop and could've appended the data. That way you could've avoided the second for loop.
@antongjoka8533
@antongjoka8533 3 года назад
Ma mann thank you, this tutorial is so good, dislikes are from haters.
@shirleysiu5958
@shirleysiu5958 2 года назад
34:36 you may use let instead of var to avoid the complicated nest function calls, but you would lose some backward compatibility with older browsers
@sontustripura3133
@sontustripura3133 4 года назад
Love your work
@DennisIvy
@DennisIvy 4 года назад
Thank you :)
@aavlasti
@aavlasti 4 года назад
Hi Dennis! Great tutorial as always the best explanation on youtube. But I have a question, that confuses me a little. Why we use JS at all, why we don't do this with python if we already have the backend there? Is this like standard, I mean without JS we cannot provide something to the view? Thank you!
@SaSha-hb5rq
@SaSha-hb5rq 4 года назад
JS is language of browser, if you want your website to be modern, dynamic you have to implement JS. You can use django without JS at all but the aesthetic of web will not as good as
@realdaly
@realdaly Год назад
I have the same question, I guess in real world apps you would make your projects separate, like the api project hosted some where and HTML, JS project (React probably) hosted somewhere else.
@Copt774
@Copt774 21 день назад
for the strikethrough on items, i added this inside the build function and it did the trick. Using react for state management would make this so much more pleasurable!! - var strikeItemTitle = document.getElementById(`title-${i}`) if (list[i].completed === true) {strikeItemTitle.setAttribute("style", "text-decoration: line-through")} else { strikeItemTitle.removeAttribute("style")}
@rubelnl1
@rubelnl1 3 года назад
Great Explanation as Before
@kamilwaszewski
@kamilwaszewski 4 года назад
Hi Dennis! First of all I want to say thank you. You make really great content! Keep working like that :) I have also a couple of questions. Maybe you could give me some advices. I'm building a language learning app, kinda flashcards based app. I have users, each user should be able to add folders, each folder can consist multiple decks with flashcards, also some options like add tags or displaying infos about certain folder or deck etc. And such kind of dealing with creating/updating and displaying particular folders, decks and flashcards (and some extra options) is ideal to use AJAX, to not realoading the page etc, these are just some lists with extra pop-ups to display those extra infos. Is it a good option to use this kind of api? I need updating and getting data based of logged user, also want to use multiple models, some foreign keys, because I need for example display info about deck based of some data about flashcards etc. You also set some html in your javascript code, to generate items etc, but my content seems more complex, so is that good way to put that html in js code? If not, how can I generate some stuff based on what user is gonna do? Summarizing, what's a good way to deal with things that I want, with multiple models, and the models depend on each other and also generated view is more complex than just title or basic info (they consist for example extra pop-up, images etc)? Thanks for some advices :)
@namanjoshi5089
@namanjoshi5089 6 месяцев назад
wow ...Thanks a lot for this awesome content!
@PritpalSingh-kz6kt
@PritpalSingh-kz6kt 3 года назад
Thanks man you helps me alot to complete my tasks
@MrYoklmn
@MrYoklmn 4 года назад
Денис, это шикарно! Спасибо огромное)
@DennisIvy
@DennisIvy 4 года назад
Пожалуйста :)
@Dante-fk4yi
@Dante-fk4yi 4 года назад
Он крут
@MrYoklmn
@MrYoklmn 4 года назад
@@Dante-fk4yi О, я не один такой с комментами на русском) Он крут не то слово!!!
@darwinsterritory
@darwinsterritory 3 года назад
@@MrYoklmn Нас много)
@abdulkaderzilani1825
@abdulkaderzilani1825 4 года назад
Excellent work, Also hope a tutorial "schedule request" (celery)with drf and build a aweome series with drf
@DennisIvy
@DennisIvy 4 года назад
Thanks for the recommendation :)
@sazzadahmed200
@sazzadahmed200 4 года назад
Hi Dennis! First of all thanks to you for this amazing tutorial. So, I think I was found the best solution for preventing the flash when we call buildlist(): code: data.forEach((el, ind) => { let title = `${el.title}` if (el.complete) { title = `${el.title}` } let item = ` ${title} Edit Delete ` html += item; }); wrapper.innerHTML = html;
@maahad767
@maahad767 3 года назад
Thanks, learned a lot. Opened a pull request ;P Consider looking into it.
@sangle3615
@sangle3615 3 года назад
Thank you for your wonderful lesson!!!
@sivaprasadkommula6820
@sivaprasadkommula6820 Год назад
when i try to update the task a new task is added to the list. I can't figured the mistake what i done, can anyone help me !
@rangabharath4253
@rangabharath4253 4 года назад
Awesome. Thank u so much Dennis.
@eliyir
@eliyir 3 года назад
Thank you Dennis!
@augus7587
@augus7587 Год назад
Why are we using the rest framework and api. When we can build a todo site with only django.. can anyone tell me the difference ?
@theanonymous92
@theanonymous92 9 месяцев назад
Yes you can build todo application using django a beautiful frontend using templates and logic in views nice and simple. but say today you built it and it's working great --- tomorrow you want to explore something else say react native (for andriod app ) and you want to create a todo application in it too now there are two ways to do that 1. create frontend and along with it write the logic for application functionality from scratch Or just create frontend in react native and reuse your well written backend of 'todo application' ( that you wrote for django app) as an api for this application too. so now there is only one backend but two applications 1. a webapp 2. a mobile app running on top of that using the api you had created --- speaking of DjangoRestFramework well it's just a recommended library for creating your api specifically designed to work with django --- you may use it or may just use django and create api without it that's upto you ---but if you do use it; it does provide nice features
@ashishneupane7180
@ashishneupane7180 4 года назад
For those who are waiting for Dennis's React TODO project with RESTApi. ... I have done the same project using Vue.js with DjangoRestapi.......link : github.com/Aasess/Django-RESTAPI-Vue.js
@sontustripura3133
@sontustripura3133 4 года назад
Awesome man! Love it
@temiloluwaadeoti4322
@temiloluwaadeoti4322 4 года назад
**Question @33:41**: Do you think it's a good idea to use the Jquery Event Handler Attachment function (on)? I used it in the for-each call and it appears to bind the right data for each button to its respective event-listener.
@perfectigbadumhe113
@perfectigbadumhe113 4 года назад
Cool awesome tutorial hoping the knowledge from this will help in doing like a check box where I can select multiple element then edit all of it with just a single text and a click of a button
3 года назад
16:40 - In my case, I had to made an amendment to what is line 127 on your screen at the time. I changed it to var list = data.results as my drf returns the number of objects and a bunch of other headers. I believe that you might have disabled that in your first video but I came straight here so if there is anyone out there wandering why they are getting errors, this maybe one of the reasons.
@vucuong6767
@vucuong6767 4 года назад
Thanks for your helpful tutorial videos. Hope you have a series combination of django and react (native)
@SunriseBusinessClub
@SunriseBusinessClub 4 года назад
Hi Dennis! Question: why u write 'frontend.apps.FrontendConfig' instead of 'frontend' (app's name)? Thanks! Why do we need to write it so? Also, why we add 'rest_framework'? It is not an app as I understand..., or is it just a rule of thumb?
@touchtbo
@touchtbo 3 года назад
This is a great video
@faizzulpa8444
@faizzulpa8444 4 года назад
Hi Dennis, thank you for the great contents. I have learnt a lot from your videos. I am trying to follow this video too but I have no knowledge on Javasript, is it possible or should i learn javasript first ?
@faizzulpa8444
@faizzulpa8444 4 года назад
anyone reading this i will answer by myself, yes you do need to know javascript. thnk you!
@cadeepaktayal
@cadeepaktayal 4 года назад
Great tutorial...can you please suggest how to use dynamic url instead?
@asameshicode
@asameshicode 3 года назад
A little trick I did was to use Django template and secretly display the URL on the HTML and retrieve that URL with. You can get the full url path by using this: {{ request.build_absolute_uri }}{% url 'your URL name' %}
@asameshicode
@asameshicode 3 года назад
Sorry, use this instead: {{ request.META.HTTP_HOST }}
@emperorpalpatine7808
@emperorpalpatine7808 3 года назад
Hello! I may have found a easier way to manage the "edit" and "delete" keys. You can create a function with the id as a input which send the fetch request and stuff. You can then call it inside the dom using onClick HTML method and pass in the id using template literals.
@realdaly
@realdaly Год назад
What if I wanna deploy the api app only and use my endpoints in another website uploaded on some other platform like netlify?
@ganaskylight
@ganaskylight 3 года назад
Hey man, i love your tutorials. Keep up the good work! By the way, the issue at 32:12 can be solved by using "let i" instead of "var i"
@skatiktajwarsihan9306
@skatiktajwarsihan9306 3 года назад
Yes, because of the previous iteration the value for "i" remains the last value. Thus it was only accessing the last element of the list.
@dmitrymikhailovnicepianomu8688
Amazing
@rangabharath4253
@rangabharath4253 4 года назад
Awesome. Thank u so much
@DennisIvy
@DennisIvy 4 года назад
:)
@HappyAnimals3D
@HappyAnimals3D 11 месяцев назад
Hi Dennis, you have another Django todo app video on your channel. is it totally different from that one?
@umairramay8041
@umairramay8041 4 года назад
Hey @Dennis I want to show unique items like first todo for ID =1 on another URL like the api we built for unique items. Means only given id item to be displayed. is there a way we can do that? I know it's a bit confusing comment but I hope you get what I want to say. And any kind of help would be very kind of you.
@sharifahmed1925
@sharifahmed1925 4 года назад
Hi guys, I keep getting the following error in the browser Console (via Chrome Dev Tools) at 13:15 when first running the builList() function Its supposed to list the entries from the api but I'm getting this error. Access to fetch at '127.0.0.1:8000/api/task-list/' from origin 'localhost:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. Any thoughts?
@procoder3715
@procoder3715 4 года назад
I am having the same issue also
@jimbim5945
@jimbim5945 4 года назад
you need to install and use django-cors-headers github.com/adamchainz/django-cors-headers
@sharifahmed1925
@sharifahmed1925 4 года назад
Here's a video on how to deal with this issue: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-EY6HhmGDLsg.html&feature=emb_logo
@almelkytech456
@almelkytech456 Год назад
Very thank you!
@YasithaNadeeshan94
@YasithaNadeeshan94 3 года назад
Thank you very much!!! useful tutorial....
@yorker3148
@yorker3148 2 года назад
thanks ! good info
@redabenyoub7734
@redabenyoub7734 3 года назад
thank's a lot, u'v rockd it at all
@paristonhill2752
@paristonhill2752 3 года назад
Thanks for the good tutorial. However what you did with the edit and delete event listeners was very poorly explained.
@naimurhasanrwd
@naimurhasanrwd 3 года назад
One word for you, 'Genius'.
@duttybwoy556
@duttybwoy556 2 года назад
i got my rest Api created and perfectly functional but I do the post method Javascript using fetch() part and it's perfectly written and doesn't give me any errors but it DOES NOT get saved on the database sigh 😫... this ishhh is giving me a big headache...because something that's literally impossible is happening... the url I pass is the endpoint I have on my api for posting stuff (when I post stuff from the django rest framework interface it does work and gets saved) but does not get added on the database from the frontend interface using js... and I've written every single line of code as shown in the video.... the fuction submit does work and run from top to bottom, and zero errors reported... but it just does NOT get added on the database.. 🤷🏽‍♂️ 🤷🏽‍♂️ 🤷🏽‍♂️ No idea... I'm lost and confused and dissaponted asf
@andrewbaehr7081
@andrewbaehr7081 3 года назад
Thank you very much
@xiaofenxia
@xiaofenxia 4 года назад
awesome,I love it
@azaderdogan2559
@azaderdogan2559 3 года назад
thank you so much sir
@semeradstephan
@semeradstephan 3 года назад
why on minute 32 you dindt just do : Edit?
@eduardoquesquen4953
@eduardoquesquen4953 4 года назад
I was looking for django videos series, number 13, but I couldn't find it
@DennisIvy
@DennisIvy 4 года назад
That one was supposed to be pagination but I had to skip it due to time constraints. I'll get it added soon :)
@eduardoquesquen4953
@eduardoquesquen4953 4 года назад
@@DennisIvy thanks, I'll be waiting for that, Blessings
@sunilghimire6990
@sunilghimire6990 4 года назад
How can we do auto reload page in django,so that you don't have to do reload manually?
@DennisIvy
@DennisIvy 4 года назад
When you say "auto reload page" i presume you mean re-render data? If not, why might you want to reload the page?
@aashayamballi
@aashayamballi 4 года назад
@@DennisIvyI guess he's talking about django channels/web sockets or if it is in react's term then obviously re rendering component.
@Jobin-at-CodingOutright
@Jobin-at-CodingOutright 4 года назад
he is probably talking about live server extension of VSC but it doesn't work with django
@aashayamballi
@aashayamballi 4 года назад
@@Jobin-at-CodingOutright yeah might be 😄
@goku-rd4zw
@goku-rd4zw 3 года назад
Hi, Dennis I'm facing a problem "Uncaught (in promise) TypeError: Cannot read property 'addEventListener' of undefined". I followed everything what you have explained. Still, I'm facing this issue. At 31:52.
@bryandadiz5677
@bryandadiz5677 4 года назад
Why do you need to have rest why not use Django only. Its a noob question but i just wanna know
@DennisIvy
@DennisIvy 4 года назад
That's a very practical question :) You technically don't need to use REST but its a common practice today because lots of websites use frameworks such as React and Angular or just use Javascript to render data. This is common because of AJAX lets us make our websites more dynamic and allows us to load/re-render data without reloading the page each time. A perfect example would be when we add or delete an item. Because of our API we are able to make a call to the database and re-render our list without ever needing to reload the page. Hope that makes sense :)
@packo280349
@packo280349 4 года назад
hi Dennis i have a issue, in min 22:40 when a submit a new item, it does duplicate my task but it dosent add my new item, i have no idea that's what happen ? javascript code var form = document.getElementById('form-wrapper') form.addEventListener('submit', function(e){ e.preventDefault() console.log('Form submitted') var url = '127.0.0.1:8000/api/task-create/' var title = document.getElementById('title').value fetch(url,{ method: 'POST', headers: { 'Content-type':'application/json', }, body:JSON.stringify({'title':title}) } ).then(function(response){ builList() }) })var form = document.getElementById('form-wrapper') form.addEventListener('submit', function(e){ e.preventDefault() console.log('Form submitted') var url = '127.0.0.1:8000/api/task-create/' var title = document.getElementById('title').value fetch(url,{ method: 'POST', headers: { 'Content-type':'application/json', }, body:JSON.stringify({'title':title}) } ).then(function(response){ builList() }) })
@packo280349
@packo280349 4 года назад
img source imgur.com/a/4FxDP8J
@scriptkid4561
@scriptkid4561 3 года назад
what are the benefits of using this over a react Django rest type architecture?
@kalkulus174
@kalkulus174 3 года назад
Thanks for sharing... We won't forget to subscribe.
@DennisIvy
@DennisIvy 3 года назад
Appreciate it :)
@asmmisfar
@asmmisfar 4 года назад
hello sir, won't u continue this series? this is awesome series. please add more videos about this. thanks
@hasimhasimov2158
@hasimhasimov2158 4 года назад
Hello Dennis, this is an amazing video but I have a question when I send request, that error occurred "Unsupported media type"
@KevinTempelx
@KevinTempelx 4 года назад
Thank you!
@Magistrado1914
@Magistrado1914 4 года назад
Excellent videotutorial 01/08/2020
@ayushsrivastav6229
@ayushsrivastav6229 3 года назад
my create function worked but i didnt submit my csrf token can anyone explain why?
@christrip
@christrip Год назад
Anyone point me to any similar videos to work within the structure of Django RESPT API + Javascript but to additionally integrate OpenAI's text completions to let's say, add a "Assist" button to send the ToDo list item title to OpenAI and to receive and display a response from OpenAI? Love your videos Dennis. Thank. you for your time.
@yacinerouizi844
@yacinerouizi844 3 года назад
thank you
@markadam9994
@markadam9994 3 года назад
hey! dennis, I didn't get the same item while clicking the edit button(with this part 👇) as you got, but pretty much i followed you everywhere.I have used custom http library using fetch and promises, that was the little change i did.But i don't think that, this should be problem solver in this case. ``` for(let i in list){ let editBtn = document.getElementsByClassName("edit-button")[i] editBtn.addEventListener('click', function(){ editItem(list[i].title); }) } ```
@shagunpreetsingh7105
@shagunpreetsingh7105 4 года назад
Hello sir, I loved the way you deliver the content, although it is more for an intermediate coder/developer. But i have a question regarding this video: Why we have to show the similar json response in our frontend - JS console aalso while we are using that Django api framework to show the same responses. SIr please answer this question asap :'))
@SaSha-hb5rq
@SaSha-hb5rq 4 года назад
You use the django api to comunicate with the Database, JS to communicate with Browser
@isaacjpg
@isaacjpg 4 года назад
Thank you !!!
@souovan
@souovan 4 года назад
Hi Dennis nice video, will you make a tutorial on consuming this API with VueJS ?
@migueljr6147
@migueljr6147 3 года назад
Why you didnt use the jinja2 in html?
@SurajKumar-vi3ll
@SurajKumar-vi3ll 4 года назад
sir, can you please tell me where the JAVASCRIPT code is?
@ishakrai435
@ishakrai435 3 года назад
Another way to solve the event listener being added to only the last item. for (var i in list){ let editBtn = document.getElementsByClassName('edit')[i] let item = list[i] editBtn.addEventListener('click', function(){ editTask(item); console.log(item); }) }
@biswadeepbhowal6758
@biswadeepbhowal6758 2 года назад
Where have you uploaded your templates?
@biswadeepbhowal6758
@biswadeepbhowal6758 2 года назад
And the static?
@amirhosseinebneroomi7280
@amirhosseinebneroomi7280 4 года назад
THE BEST
@aljon7992
@aljon7992 3 года назад
you need to update this with the latest js
Далее
Django REST Framework - Build an API from Scratch
40:39
Django REST Framework Oversimplified
9:43
Просмотров 326 тыс.
File Uploads - with Django REST Framework!
32:39
Просмотров 4,3 тыс.
Django Real Time Chat With Agora SDK
2:38:42
Просмотров 12 тыс.
Django + React Notes App
3:24:00
Просмотров 260 тыс.
Python Django REST API In 30 Minutes - Django Tutorial
30:42
Django Rest Framework | Serializers & CRUD
22:40
Просмотров 386 тыс.
Django Rest Framework for Beginners - Simple CRUD API
14:22
Django + Ajax Full Tutorial Course
46:40
Просмотров 38 тыс.