Django and React Tutorial // 2 - Handing Post Requests

  Рет қаралды 64,709

Matt Freire

Matt Freire

Күн бұрын

Пікірлер: 120
@mattfreire
@mattfreire 4 жыл бұрын
*** Please note this video is over two years old. I've left it up for those of you who might get value from it but be aware that packages update and things change. It could not work for you and that might just be because the tech has changed by now. We have a recently created (2020) course on our website that covers how to build web applications with Django and React. It is a paid course but the value you get is much more than this old tutorial. If you're interested check out learn.justdjango.com Thanks for your understanding! ***
@mundiakaluson
@mundiakaluson 3 жыл бұрын
I'm watching this is 2021. You've shown the real essence and meaning of full stack. Through referencing the web and putting everything together, you just make Python and React look like a family.
@ioan-dumitruhadarean1483
@ioan-dumitruhadarean1483 5 жыл бұрын
Really straight forward tutorial, and you are explaining really well the concepts, amazing stuff, like all your videos. I have seen Udemy tutors who are clueless about the things they teach. How can people even dislike such good videos? This is quality stuff for free.
@RahulGupta99
@RahulGupta99 3 жыл бұрын
Finished the second video of the series. Thank you for posting it. Quite informative.
@D5LR1L
@D5LR1L 4 жыл бұрын
Thank you so much. Please make more videos like this. I really like the way you teach!
@kaanberke1749
@kaanberke1749 4 жыл бұрын
Edit: Also i wanted to add this about 'this.props' . If you have a problem with it you should use props.btnText insted of this.props.btnText const CustomForm = (props: Form) => {} --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- For who has a problem on around 26:00 follow the steps: 1-) you should use onFinish instead of onSubmit 2-) Function should be like this: const handleFormSubmit = values => { console.log(values.title) console.log(values.content) }; 3-) put the name="content" and name="title" into Form.Item not Input !! Like following.. Stay safe&happy!
@Chinmay_395
@Chinmay_395 4 жыл бұрын
@Kaan Berke I am a begineer in react Did he refresh the page at 39:50 physically or it happened when he clicked on update; because when I tried it, it sends the data to the server but doesn't update [I mean reload] the page. I suspect he refreshes the page physically since, he is using "ComponentDidMount" method the page won't update. Correct?
@aliabdullahcp
@aliabdullahcp 4 жыл бұрын
that was really helpful, thanks
@metealpkzlcay4418
@metealpkzlcay4418 4 жыл бұрын
for people who facing the submit issue, change your code in Form.js file like this; import React from 'react'; import { Form, Input, Button } from 'antd'; import axios from 'axios'; class CustomForm extends React.Component { handleSubmit = (values, requestType, articleID) => { const title = values.title; const content = values.comment; const formData = new FormData(); formData.append('title', title); formData.append('content', content); const data = { title: title, content: content } switch (requestType) { case 'POST': return axios({ method: 'post', url: '127.0.0.1:8000/api/', data: formData }) .then(response => console.log(response)) .catch((error) => console.log(error)) case 'PUT': const put_url = '127.0.0.1:8000/api/' + articleID + "/" return axios({ method: 'put', url: put_url, data: formData }) .then(response => console.log(response)) .catch(error => console.log(error)) } } render() { return ( this.handleSubmit( values, this.props.requestType, this.props.articleID, )}> {this.props.btnText} ); }; } export default CustomForm
@mokraneachache5809
@mokraneachache5809 4 жыл бұрын
just use normal form instead of Form provided by ant
@ericslusarz
@ericslusarz 5 жыл бұрын
This is so good! Definitely going to watch the rest, thank you!
@adrianhelerea420
@adrianhelerea420 4 жыл бұрын
Great tutorial! The sound of your keyboard it is very nice, what are you using?
@deadfool6105
@deadfool6105 6 жыл бұрын
Man.. You are just awesome.. 😄😄😄😄
@mattfreire
@mattfreire 6 жыл бұрын
Thanks!
@markkthemk
@markkthemk 4 жыл бұрын
At 31:45 wouldn't it be better to base the put and post on whether or not the article ID is given?
@aBradAbroad
@aBradAbroad 5 жыл бұрын
Thanks again. Very easy to follow. Looking forward to the next one.
@silvaXX-st9nh
@silvaXX-st9nh 6 жыл бұрын
Another home run, Thanks for being awesome.
@Paul-qn7qv
@Paul-qn7qv 5 жыл бұрын
At 33:51, why wouldn't you store `articleID` inside `componentDidMount`? This way you won't have to access `this.props.match.params.articleID` twice.
@Fernandocontreras117
@Fernandocontreras117 4 жыл бұрын
Bro, you are a crack!!!, thanks a lot for all your great videos
@hozayfaelrifai8841
@hozayfaelrifai8841 6 жыл бұрын
and thanks for recording
@ChaminNalinda
@ChaminNalinda 6 жыл бұрын
While making post/put request from React, I got "An established connection was aboarted" error in my Django Backend. how ever, in terms of functionality it's working, is there a reason why this happens. Thanks
@mdellertson
@mdellertson 5 жыл бұрын
Yes, it's because stackoverflow.com ;-P
@wah1dx
@wah1dx 4 жыл бұрын
Hey if you found the solution then pls share it here, I'm stuck here for 2 days now
@wah1dx
@wah1dx 4 жыл бұрын
@@mdellertson Can you be more specific bro.
@santiagotorres6929
@santiagotorres6929 4 жыл бұрын
@@wah1dx It's a joke dude...
@wah1dx
@wah1dx 4 жыл бұрын
Bro after removing event.preventDefault(); I'm getting network error, The page refreshes but the api call is not working. Thanks
@mubashshiralibaig6104
@mubashshiralibaig6104 5 жыл бұрын
put is not updating the article. I did everything as mentioned in the vid but on clicking it just reloads the page and show the same title and content
@hellokitty13577
@hellokitty13577 5 жыл бұрын
put a / after ${articleID}
@kevinxin1545
@kevinxin1545 4 жыл бұрын
I just wanna know what keyboard you are using XD
@Paul-qn7qv
@Paul-qn7qv 5 жыл бұрын
At 34:43, it's `console.error` not `console.err`
@mathiasbramstorp281
@mathiasbramstorp281 4 жыл бұрын
i cant access the /id cors is blocking the part but i can see the whole api on the homepage but only when i click on one of the object i get this message i worked before chaning around setup also when i click the api link i get the object. Access to XMLHttpRequest at '127.0.0.1:8000/api/1' from origin 'localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
@husseinsaad7969
@husseinsaad7969 6 жыл бұрын
Perfect, keep going!
@mbaye501
@mbaye501 6 жыл бұрын
Just wondering how would l deploy this on a platform like Heroku ? successfully deploy pure Django project before but not sure about combining react + Django
@mattfreire
@mattfreire 6 жыл бұрын
Looking at posting a video on this sometime. At the moment I would say you host the Django rest framework on heroku and use firebase for your frontend
@BRJWON
@BRJWON 4 жыл бұрын
removing preventDefault is still not helping refresh db call. Can someone help with this.
@limyeewee3518
@limyeewee3518 3 жыл бұрын
Hi, same problem here. Did you manage to fix it?
@xXshozzyXx
@xXshozzyXx 3 жыл бұрын
@@limyeewee3518 add window.location.reload() at the end of each case
@sahiltrivedi69
@sahiltrivedi69 4 жыл бұрын
Great work thank you so much this is priceless :D
@Chinmay_395
@Chinmay_395 4 жыл бұрын
why does it give an error if you put the createView URL path after detailView. Is there a reason why this happens?
@muzafferckay2609
@muzafferckay2609 4 жыл бұрын
Hi, why does Django return errors if we put path('create/', ArticleCreateView.as_view()). bottom path('/', ArticleDetailView.as_view()) in api urls. it return Article detail when scan 127.0.0.1:8000/api/create/ on browser.
@NavjotSingh-so8jb
@NavjotSingh-so8jb 4 жыл бұрын
my form.js page is not responding when i click submit ??? what to do plzz help?
@anamariaafanasov2100
@anamariaafanasov2100 4 жыл бұрын
I got stuck with the same problem. Have you found any solution?
@abednegowambua7990
@abednegowambua7990 4 жыл бұрын
@@anamariaafanasov2100 you can use onSubmitCapture instead of onSubmit
@harekowicz
@harekowicz 6 жыл бұрын
Great tut! Do you have any idea why handleFormSubmit event just refreshes the page without executing the rest event code? Putting event.preventDefault() fixes the issue but the page is not being refreshed. Thanks a lot in advance! Cheers!
@mattfreire
@mattfreire 6 жыл бұрын
+harekowicz in most react applications the aim is not to refresh the page because you are normally storing data in the state of your application that would be lost if you refreshed. Instead you’d show a spinner to tell the user that some action is taking place
@hamyazilim
@hamyazilim 4 жыл бұрын
Awesome tutorial.
@castilloalexander739
@castilloalexander739 6 жыл бұрын
I have a query, I have done everything as indicated in the video, but when I want to go to the detail view from the frontend application, the following message appears in the browser console - the CORS header is missing: 'Access-Control -Allow-Origin ' ... by the way, I thank you very much for the series of videos, excellent work!
@mattfreire
@mattfreire 6 жыл бұрын
You don't have corsheaders installed. corsheaders lets you specify urls that are allowed to interact with your server. You can install it yourself or check the github repository (in the description) to see how it was used
@castilloalexander739
@castilloalexander739 6 жыл бұрын
In fact, I have it installed and configured as shown in the first video of the series. in the doubt of whether I had done the procedures well, I took the time to do a new project and the results are the same
@castilloalexander739
@castilloalexander739 6 жыл бұрын
I will continue searching for a solution, if I find it I will share it with you.
@manukyanq
@manukyanq 5 жыл бұрын
l got the same trouble .If everything is ok with corsheaders look your url.py file, maybe you has missed "/" in your url patterns or in axios.get method
@TheArtsyPig
@TheArtsyPig 5 жыл бұрын
Did either of you find a solution?
@sahileliyev2600
@sahileliyev2600 6 жыл бұрын
You are perfect, keep it up, it is enjoy to learn from you)
@alihusham1560
@alihusham1560 4 жыл бұрын
you are awesome and django is awesome super thank you
@lukavicic4676
@lukavicic4676 4 жыл бұрын
PUT method updates article but also creates a new one with same title and content. Anyone has this problem?
@Zzzzzzzzzzzzzzzzzzzzr
@Zzzzzzzzzzzzzzzzzzzzr 6 жыл бұрын
Your Good! If your not in america men Bet alot of companys would want to hire you quick
@jmarqsmachariah5720
@jmarqsmachariah5720 4 жыл бұрын
Am stuck, why are my PUT and Post requests not working. Get is working ok. Anyway your explanation is superb
@doyourealise
@doyourealise 5 жыл бұрын
You're accessing the development server over HTTPS, but it only supports HTTP. how to solve???
@paulluu3682
@paulluu3682 5 жыл бұрын
Shouldn't we have a "break" in each case of switch statement?
@ilies112
@ilies112 5 жыл бұрын
in that case he did put return which allows us to break automatically
@mbaye501
@mbaye501 6 жыл бұрын
great vid man
@abhijeetpal2098
@abhijeetpal2098 6 жыл бұрын
Can anyone please tell me can I use any react package? Because it is independent of backend?
@vladventura1928
@vladventura1928 5 жыл бұрын
I'm pretty positive you can
@ichbinderkonig4049
@ichbinderkonig4049 6 жыл бұрын
Great job, thanks a lot
@mukeshchugwani2274
@mukeshchugwani2274 5 жыл бұрын
Great Video!
@alihusham1560
@alihusham1560 4 жыл бұрын
I got 5000 error with put request any help?
@oyejohnson
@oyejohnson 6 жыл бұрын
how do i go about auth with django and react, please help its urgent
@irayyamathad6838
@irayyamathad6838 5 жыл бұрын
Best tutorial
@zhmen007
@zhmen007 4 жыл бұрын
Hi, onSubmit does not work for ant 4.*, how to fix it? Thanks.
@jacksonkupris994
@jacksonkupris994 4 жыл бұрын
const title = document.getElementById('title').value; const content = document.getElementById('content').value; also use onFinish instead of onSubmit.
@chrislarson8128
@chrislarson8128 4 жыл бұрын
@@jacksonkupris994 To add on to this for others who might need help with ant 4: this.handleFormSubmit(values, this.props.requestType, this.props.articleID )}> {this.props.btnText}
@maurienyt
@maurienyt 4 жыл бұрын
@@chrislarson8128 Hey guys, did you had some Error: Request failed with status code 403 ?
@arivannadih4230
@arivannadih4230 4 жыл бұрын
the page isn't reloading aftere removing the preventDefault()? Can anyone help me?
@jamesd1950
@jamesd1950 4 жыл бұрын
window.location.reload(false) I think this will work. put this in .then(res=>{console.log(res);window.location.reload(false);})
@santiagotorres6929
@santiagotorres6929 4 жыл бұрын
2:1 Access to XMLHttpRequest at '127.0.0.1:8000/api/2' from origin 'localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Any idea about how to fix this problem, I've been looking up on all sites and haven't found anything yet...
@josephmwangi1951
@josephmwangi1951 5 жыл бұрын
Thank you...so so much.
@jgartsu12
@jgartsu12 4 жыл бұрын
very helpful!
@БорисБ-е7т
@БорисБ-е7т 6 жыл бұрын
Thanks a lot!
@Temea-pw5bv
@Temea-pw5bv 3 жыл бұрын
you are a great man you better than messi 😃 please move up and still post videos in your chanell
@darren1107
@darren1107 4 жыл бұрын
I'm really stuck on this onSubmit not working.. I think I'm going to have to move on to another tutorial for now
@darren1107
@darren1107 4 жыл бұрын
@@asifcoer you need to use onFinish
@siddharthramawat3713
@siddharthramawat3713 4 жыл бұрын
@@darren1107 I tried replacing onSubmit with onFinish it didn't work
@santiagotorres6929
@santiagotorres6929 4 жыл бұрын
onSubmitCapture, try this one, and lemme know if something goes wrong...
@KevinKamauk
@KevinKamauk 5 жыл бұрын
Doing this in 2019 with React version 16.11, i'm getting 'Warning: componentWillReceiveProps has been ....' I understand it has to do with Lifecycle methods being deprecated, this also impacts some of the code from antd, is there anyone who has come across this issue?
@simonjohn8374
@simonjohn8374 5 жыл бұрын
Kwani unapata error bado au ushasolve
@KevinKamauk
@KevinKamauk 5 жыл бұрын
@@simonjohn8374 resolved. I realized I'm not affected since I'm only using componentDidMount() instead of componentWillMount (). Only then would I have needed to rename the components.
@simonjohn8374
@simonjohn8374 5 жыл бұрын
Okay that is better
@spaceman1
@spaceman1 6 жыл бұрын
Access to XMLHttpRequest at 'localhost:8000/api/1' from origin 'localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
@mohammedsalman3397
@mohammedsalman3397 6 жыл бұрын
where is the 3rd tutorial? please make more
@mamatkasymmamatkulov2530
@mamatkasymmamatkulov2530 4 жыл бұрын
Cool
@Thesrik23
@Thesrik23 6 жыл бұрын
How many more to come in this series??
@mattfreire
@mattfreire 6 жыл бұрын
Not to sure at the moment. Could be doing one or two more
@husseinsaad7969
@husseinsaad7969 6 жыл бұрын
could you make a video on REST framework JWT Auth? please. @justDjango
@anonuser1366
@anonuser1366 4 жыл бұрын
good video)))
@vjp2866
@vjp2866 5 жыл бұрын
Is that mac keyboard producing that tap sound?
@juanoleas1287
@juanoleas1287 4 жыл бұрын
I'm having issues with not being able to submit a PUT or a POST request using the frontend form. I think the issue for mine is with the switch (requestType) statement. Does anyone have a solution and have their code be able to "create" or "update" the articles through the frontend? This is what my current Custom Form looks like: class CustomForm extends React.Component { handleForm = (values, requestType, articleID) => { const title = document.getElementById('title').value; const content = document.getElementById('content').value; console.log(values, requestType, articleID); switch (this.props.requestType) { case 'post': axios.post(API_URL, { title: title, content: content }) .then(res => console.log(res)) .catch(error => console.log(error)); break; case 'put': // return axios.put(API_URL + articleID, { axios.put(`localhost:8000/api/${articleID}/`, { title: title, content: content }) .then(res => { console.log(res); window.location.reload(); }) .catch(error => console.log(error)); break; } } render() { return ( this.handleForm( values, this.props.requestType, this.props.articleID )}> {this.props.btnText} ); }; }
@escrituratalks
@escrituratalks 4 жыл бұрын
@@mrb13676 Does it make any difference writing the request types in lower or upper case? For me it works fine both ways
@maciejscibor
@maciejscibor 5 жыл бұрын
kudos
@cyrilmmojekwu9331
@cyrilmmojekwu9331 4 жыл бұрын
At this time (May 2020), This video is outdated!!!. Do update it, thanks.
@wseling
@wseling 5 жыл бұрын
The page at: github.com/justdjango/DjReact.git does not match up with your video! Maybe it used to but not today. I'm using the original commit from Jul. 30, 2018.
@mattfreire
@mattfreire 5 жыл бұрын
+wseling you need to reset back to the commit at the start of this video
@milankathiriya3635
@milankathiriya3635 6 жыл бұрын
Great videos man.... However I try with image field and facing problem with uploading. It just cant done. I try with: Click to upload To upload image in media folder in src folder. I also well setup MEDIA_ROOT and MEDIA_URL in settings.py However when Itry to upload, console raises with: POST 127.0.0.1:8000/media/ 0 () 127.0.0.1:8000/media/:1 How can I get rid from this??? It will be greatly appriciated if you tell what to do.... Waiting for your acknowledge.
@migueltenorio9998
@migueltenorio9998 4 жыл бұрын
Subtítulos en español please
@chantzoul
@chantzoul 4 жыл бұрын
great video, but i can't stand the sound of your mac lmao
What is the future of Django / Is Django becoming obsolete?
19:35
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
人是不能做到吗?#火影忍者 #家人  #佐助
00:20
火影忍者一家
Рет қаралды 20 МЛН
Full Stack React & Django [2] - Implementing React
31:14
Traversy Media
Рет қаралды 204 М.
React + Django Integration Tutorial | Hello World App
11:01
Dennis Ivy
Рет қаралды 243 М.
7 concepts you should know to get a job as a Django developer
23:12
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 220 М.
Python Django Web Framework - Full Course for Beginners
3:45:41
freeCodeCamp.org
Рет қаралды 4,8 МЛН
Python Django Introduction and Beginners Tutorial
27:29
Dave Gray
Рет қаралды 75 М.
Django + React Notes App
3:24:00
Dennis Ivy
Рет қаралды 264 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН