Тёмный

Connect Django Backend to React.js Frontend - Full Stack App Development Tutorial 

Bek Brace
Подписаться 28 тыс.
Просмотров 119 тыс.
50% 1

In this full stack app development tutorial, I will show you how to connect a Django backend server to a React.js frontend user interface. This is an important step in creating fully fledged apps, and as a full stack developer, it's crucial that you know how to do this. We'll guide you through the process step-by-step, using Python, Django, and React.js. Watch this video now to learn more!
#fullstackdevelopment #django #reactjs #python #backenddevelopment #frontenddevelopment #appdevelopment #webdevelopment #coding #programming #tutorial
Source Code: github.com/BekBrace/React-Tut...
Join this channel to get access to perks:
/ @bekbrace
#django #react #reactjs #reacthooks #javascript #djangorestframework #djangoframework #python #pythonprogramming #javascript #backenddevelopment #frontenddevelopment

Наука

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

 

26 мар 2023

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 153   
@BekBrace
@BekBrace 20 дней назад
Guys, if youre struggling with views.py and having issues , here's a better way to write ✍️ views.py using generics: from rest_framework import generics from .models import React from .serializer import ReactSerializer class ReactItemView(generics.ListCreateAPIView): queryset = React.objects.all() serializer_class = ReactSerializer def get_queryset(self): queryset = super().get_queryset() name = self.request.query_params.get('name') if name: queryset = queryset.filter(employee=name) return queryset Benefits of This Approach: ------------------------------------------ +Simplicity: By using generics.ListCreateAPIView, you automatically get get and post functionality without needing to explicitly define them. + Customization: The get_queryset method allows you to filter results based on query parameters, enhancing the flexibility of your API. Additional Tips: 1-CORS Configuration: Ensure that django-cors-headers is properly set up in your settings.py to avoid cross-origin issues when your React frontend interacts with the Django backend. 2- Error Handling: In your original code, you used raise_exception=True which is good practice, but make sure to handle and log these exceptions appropriately. Example of Improved settings.py : INSTALLED_APPS = [ ... 'rest_framework', 'corsheaders', ... ] MIDDLEWARE = [ ... 'corsheaders.middleware.CorsMiddleware', ... ] CORS_ORIGIN_ALLOW_ALL = True REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.AllowAny', ], }
@monasser6
@monasser6 20 дней назад
thank you so much man. U r the best ❤
@mobalaaa
@mobalaaa 20 дней назад
thank you 😊
@thekaliexpert
@thekaliexpert 20 дней назад
thanks Bek, I had problems with the fields
@wajdwael8775
@wajdwael8775 9 месяцев назад
I have never watched other tutorials teaching how to do this in that easy, straightforward way, keep going we need more full-stack videos.
@BekBrace
@BekBrace 9 месяцев назад
Thank you very much for such sweet words, really 🙏🙂 Soon a Full Stack project is to be published / Recording done and Editing in process 😉
@kenkioqqo
@kenkioqqo 9 месяцев назад
This was a nice gentle introduction to Django-React integration. I think I'll revisit it next week when I build the React frontend of my DRF project. Thanks man.
@BekBrace
@BekBrace 9 месяцев назад
Great stuff ! You're always welcome, dude !
@nnamdiekweariri
@nnamdiekweariri Год назад
Hey Amir, thanks for making these videos about Django and reactjs. I find them very useful.
@BekBrace
@BekBrace Год назад
Thank you for watching my friend 🙂
@archi124
@archi124 Год назад
Works like a charm. Great video!
@BekBrace
@BekBrace Год назад
Glad to hear my friend
@NiceChange
@NiceChange 6 месяцев назад
this is a great video. A complete course in database and front end as well as multiple servers. So much info in here you have to watch it a couple of times..Great work!!!. This one is a save.
@BekBrace
@BekBrace 6 месяцев назад
Thank you so so much for you kind words, my friend, and welcome to the channel 🙂
@ueldermartin
@ueldermartin 4 месяца назад
one of the most pleasurables tutorial I ever had Thank you mate
@BekBrace
@BekBrace 4 месяца назад
Thank you very much, this is very kind of you
@drummermike5150
@drummermike5150 6 месяцев назад
Excellent tutorial!! Thanks for taking the time to produce this!
@BekBrace
@BekBrace 6 месяцев назад
Thank you for watching, Mike 🙂🙏
@drummermike5150
@drummermike5150 6 месяцев назад
@@BekBrace One thing I ran into towards the end is in the settings file show at 12:47 you need corsheaders not coresheaders. The React frontend wasn't returning anything until I made this change.
@amarek5841
@amarek5841 Год назад
Hi Amir, thank you for your time and explanation, clear and concise
@BekBrace
@BekBrace Год назад
You are welcome!
@balajik1924
@balajik1924 7 месяцев назад
Thanks for your video i get the output l was struggled 2 weeks in api method output backend using django frontend using reactjs finally i made it for your video thanks @bek brace
@BekBrace
@BekBrace 7 месяцев назад
Thank you very much for watching, and I am glad you have found it useful :)
@fuadpalchayev7269
@fuadpalchayev7269 8 месяцев назад
Thank you so much! Amazing video!!!
@BekBrace
@BekBrace 8 месяцев назад
You're welcome, Fuad my friend 🙏
@dhruvborkar4943
@dhruvborkar4943 14 часов назад
Great video man. Really helpful and clear.
@BekBrace
@BekBrace 7 часов назад
Thank you, glad you found it useful :)
@franzdelossantos2828
@franzdelossantos2828 9 дней назад
Thank you so much I learned a lot and it was easy to follow
@BekBrace
@BekBrace 9 дней назад
So glad 😊 thank you for watching 👍✨🔥
@gunjankubde1289
@gunjankubde1289 3 месяца назад
Had to submit an assignment. Thanks for making me understand the concept
@BekBrace
@BekBrace 3 месяца назад
Glad I could help!
@carybondoc
@carybondoc 8 месяцев назад
This is great! There are certain typo error but using your repo helps me to troubleshoot!
@BekBrace
@BekBrace 8 месяцев назад
Thank you. I apologize for the errors caused :(
@asha6175
@asha6175 Год назад
Just subbed to your gaming channel ❤ thank you for your big effort and keep it up Amir ❤
@BekBrace
@BekBrace Год назад
Appreciated
@mertmanoah7751
@mertmanoah7751 3 месяца назад
Good explanation, thanks man
@BekBrace
@BekBrace 3 месяца назад
Thank you for watching 😊
@MounirSMalak
@MounirSMalak Год назад
Great tutorial thanks 🙏
@BekBrace
@BekBrace Год назад
Glad it was helpful!
@easydevtips
@easydevtips Год назад
Great video!
@BekBrace
@BekBrace Год назад
Thank you very much.
@centralcoding
@centralcoding 3 месяца назад
this is what I want to learn bro. you did great & thank you I need more videos on react and django. Im your top fan now. And please i will be happy if you work with react function based.
@BekBrace
@BekBrace 3 месяца назад
Central Coding, thank you so much my friend 🙏
@vishalparkar
@vishalparkar 5 месяцев назад
Thanks a lot !
@BekBrace
@BekBrace 5 месяцев назад
You're very welcome my friend 🙏
@nileshvishwekar9906
@nileshvishwekar9906 Год назад
Nice explained
@BekBrace
@BekBrace Год назад
Thank you 👍
@pavanvarahad9024
@pavanvarahad9024 Год назад
Hi Bek, Thanks for making this.. ,explanation was too good , can you please make a video on how handle routing with this..
@BekBrace
@BekBrace Год назад
Thanks man. Yes, i can.
@Nioxs
@Nioxs Год назад
@@BekBrace yeah would love to see what the best way to implement react router with django
@rameshkannan1776
@rameshkannan1776 6 месяцев назад
Thanks very simple and intersting.
@BekBrace
@BekBrace 6 месяцев назад
Glad you enjoyed it my friend 🙏
@SunitaShakuniya
@SunitaShakuniya 7 месяцев назад
Hey...it was really helpful
@BekBrace
@BekBrace 7 месяцев назад
Thank you for watching 😊
@opcon3155
@opcon3155 Год назад
Hello! You are awesome bro 😎
@BekBrace
@BekBrace Год назад
Thanks man
@cusematt23
@cusematt23 6 месяцев назад
Nice tutorial. One bit of feedback I would have is to try to edit out the typo's/misspellings instead of fixing later in video. A lot of people try to code along and if stuff starts breaking and its hard to figure out why (pipenv in particular makes it harder to view the virtualenv modules compared to says venv) people will get confused/tilt/start over like I just did. But I mean hell overall it still definitely added value for me so thank you.
@BekBrace
@BekBrace 6 месяцев назад
Thank you very much for your feedback, much appreciated 🙏 And I really apologize if you had any confusion, I'll definitely make sure to do that in my future videos. Please if you have any questions, don't hesitate. Cheers!
@cusematt23
@cusematt23 6 месяцев назад
@@BekBrace thanks mate. Yes definitely a great tutorial overall that cleared up a ton of my confusion!
@cusematt23
@cusematt23 6 месяцев назад
Only thing I can't figure out is how you got your model fields to display in the API. Mine is still expecting json format when I post. If you have any idea. I tried adding the browsable API view with no luck.
@cusematt23
@cusematt23 6 месяцев назад
AH I see someone posted a solution below. Many thnks.
@MarekDerlukiewicz
@MarekDerlukiewicz Год назад
Hi Bek, I have prepared an app - backend in django and frontend in react; is there any possibility to publish it e.g. on github pages to see it working together? Or maybe there is another way to do this?
@BekBrace
@BekBrace Год назад
Hi Marek 👋 yes sure, check out Heroku. You can publish full stack apps like yours on Heroku, also it's possible in Netlify I believe
@ryostyles9904
@ryostyles9904 6 месяцев назад
Allowing requests from any origin actually compromises the security, you need to allow only specific hosts to consume your API
@BekBrace
@BekBrace 6 месяцев назад
Yes that's absolutely correct! In production I would never do that , and I have other tutorials where I have disabled the Allow Any, and specifically determined which sources I want to consume.
@vasilisplevris5103
@vasilisplevris5103 11 месяцев назад
Hello, i was following this turorial but at this time 15:58 my interface looks somewhat different Instead of the two fields you have(employee and department) i have a field called "MediaType" which is a dropdown menu and then another field called "Content" which basically is a huge textbox to right things. I am pretty sure i followed the tutorial correctly, but i can't figure for the life of me why the fields are different Any ideas or solutions would be appreciated. Edit:Also i don't have the Raw Data and HTML form options PS: I am on windows 10 if that helps
@OmRon-zf9qe
@OmRon-zf9qe 10 месяцев назад
have u found a solution yet bud?
@goosedotpy
@goosedotpy 10 месяцев назад
i made a video solution
@33319987
@33319987 8 месяцев назад
@@goosedotpy It's working thanks!
@user-uj7mj5wh7m
@user-uj7mj5wh7m 7 месяцев назад
I also the same result, first box is drox selection box and the title is Media type, why it happens?
@samerco11
@samerco11 6 месяцев назад
@@goosedotpy thanks it works for me
@MushyRoo
@MushyRoo 5 месяцев назад
Hey Thanks a lot ! I have a doubt can you please help me with it Suppose im using an API from a website say Google to get certain details , it returns me a JSON file , how can i use this API so that it returns data inside REST framework How am i supposed to go ahead with this
@_vietdava_
@_vietdava_ 12 дней назад
very good
@BekBrace
@BekBrace 11 дней назад
Cheers
@jonaallwin570
@jonaallwin570 3 месяца назад
Heyy, great video man I'm kinda new to this react+django scene and this tutorial was amazing. I have a dumb question though, what is the architecture called, does it even have a name or something.
@BekBrace
@BekBrace 3 месяца назад
Thanks a lot for your kind words. You mean stack name ? If yes, then no it doesn't have a stack name like MERN or LAMP stacks.
@nnamdiekweariri
@nnamdiekweariri Год назад
Hi Again, I have a question for you. In your "Full Stack Project with React.js and Django", you mentioned that we can just call Model.objects.all() in the views file... But here, you have written a get and post functions. What are the key difference from both? I my opinion, they both work but it seems you wanted to be more explicit.
@BekBrace
@BekBrace Год назад
Hi :) you can retrieve data from a database in multiple ways. One way is to use the Model.objects.all() method, and another way is to define custom GET and POST functions.
@BekBrace
@BekBrace Год назад
The key differences between both are as follows:
@BekBrace
@BekBrace Год назад
1) Model.objects.all(): This method is used to retrieve all objects from a particular model. It returns a queryset, which is a collection of model instances. You can use this method to retrieve all the data from the database and pass it to the frontend to display.
@BekBrace
@BekBrace Год назад
2) Custom GET and POST functions: These functions are defined in the views.py file as you said, and allow you to define your own logic for handling HTTP GET and POST requests. You can use these functions to filter data based on certain criteria, perform additional operations on the data, and return a customized response.
@nnamdiekweariri
@nnamdiekweariri Год назад
Thanks a lot for your explanations.
@DevlogBill
@DevlogBill 10 месяцев назад
Very interesting, let me see if I understand what you did. Basically you created an API with Django and you are having React view the API which is created from Django. So React is using something called AXIOS to get the API which you created using Django. I made a bunch of API's already with Django, I think about 12 now. All I need to do is learn React. Or would you recommend I learn more about Django before jumping into React? Still kind of new with Django only 5 months, thanks for the video Ben. I hope to learn more from you.
@BekBrace
@BekBrace 10 месяцев назад
Hey friend، it's great to hear from you !! Regarding your question. 1- on a scale from 1 to 10, 1 being the lowest and 10 being the highest, how comfortable are you with Django framework? 2- You can start learning React already as it's not connected directly to Django, I mean you being neweby or savant in Django won't affect your learning process in React, the only thing I'd advise you is to get your JavaScript level revised, if you're not ok in JavaScript then don't start learning React yet. 3- Have you created enough projects with Django? On my channel, you'll find different Django projects and I'll start again posting big projects with Django and other frontend frameworks as this was requested by many many on the channel. Good luck my friend.
@DevlogBill
@DevlogBill Месяц назад
Sorry I saw your message now. I spent more time in JavaScript for some time because my JavaScript wasn't that great. Now I am more comfortable in JavaScript and made already 1 project with React and I continue to improve in my React skills. Now I haven't used Django in a little while but I think I will spend a week brushing up on my Django skills and later try to create an API with Django for a React project. I guess if I get stuck I will refer to your videos
@jakubkuklewski4110
@jakubkuklewski4110 Год назад
is the pipenv necessary? It doesn't seem to work on my PC. Can i use regular venv instead of it ?
@BekBrace
@BekBrace Год назад
Sure, venv it'll do the same thing. You can install pipenv using: pip install pipenv
@jdcrunchman999
@jdcrunchman999 Год назад
Please do a video showing hw to enter in a forms page of data.
@BekBrace
@BekBrace Год назад
You got it
@aburayhan1897
@aburayhan1897 Год назад
that was good. but by this way i have to start two server every time. what about production? is there also going to be two server one for react and one for django?
@BekBrace
@BekBrace Год назад
Yes 2 servers
@MohamedBadr-xc7xq
@MohamedBadr-xc7xq Год назад
شكرا جزيلا يا امير، ياريت لو تعمل قناة لشرح البرمجة باللغة العربية
@BekBrace
@BekBrace Год назад
shokran
@sidds09
@sidds09 Год назад
pls do a complete project with react and drf. with auths, verfification, filters, etc.
@BekBrace
@BekBrace Год назад
I have one tutorial with react and Django, have you checked it out ?
@sidds09
@sidds09 Год назад
@@BekBrace yes.. want more and bigger.
@martiruda
@martiruda 11 месяцев назад
thanks! do you think this would work the same as using django and elm?
@BekBrace
@BekBrace 11 месяцев назад
Quite honestly, I do not know. I have never played with elm before, it's worth trying though.
@karinek6808
@karinek6808 Год назад
Hello, Thank you for this video, could you show us developing the same code but with authentication ? (cookie, csrf...)
@BekBrace
@BekBrace Год назад
Yes, sure. I will refactor the code to add authentication to it. Thanks for watching !
@user-tn7lu8je6l
@user-tn7lu8je6l 7 месяцев назад
Hi! Thank you for this great clear video. I have a problem. I get the error:" TypeError: this.state.details.map is not a function". It seems that "this.state.details" is not an array. But I checked everything. what can be the problem?
@BekBrace
@BekBrace 7 месяцев назад
Hi, thanks a lot! Yes exactly, this error usually happens when you try to call the map function on a variable that is not an array. Have you checked the GitHub code, might show you quickly the differences, you might have generated a typo.
@mirakarous5896
@mirakarous5896 Год назад
Can you please show your favorite extensions on vscode ?
@BekBrace
@BekBrace 20 дней назад
I've made one already, and there's another one coming soon
@anjaladhikari8951
@anjaladhikari8951 8 месяцев назад
Hello! It makes no difference if I don't use the ReactView and make only function based views right?
@BekBrace
@BekBrace 8 месяцев назад
Absolutely makes no difference whatsoever
@trippy_b
@trippy_b 10 месяцев назад
Is learning react necessary for django developer, Im learning projects in django with postgres as database, and bootstrap,js, jqueries for frontend.
@BekBrace
@BekBrace 10 месяцев назад
No of course not, you can create your frontend pages using django template language. If you prefer to work on the backend side, this is absolutely fine, you don't have to learn React for that; granted, it's better to learn more techs especially when they are connected, but you can learn Django on its own without touching any JS framework. Forget JQuery as Vanilla JavaScript has everything that JQuery had to offer before, so concentrate on EC6 for JS, also bootstrap is easy to learn, it will help you a lot, especially if you won't use react or vue. Good Luck, and next video is going to be Django Project where I am using Django template language and bootstrap for that matter :) - Stay Tuned
@trippy_b
@trippy_b 10 месяцев назад
@@BekBrace Thank you for clarifying this, could you please explain in short what is the advantages of using React over other frontend libraries. (in context of Django)
@BekBrace
@BekBrace 10 месяцев назад
@@trippy_b check out in my full stack playlist, you will find the first video about React for backend developers, this one will answer all your questions
@mopcse
@mopcse Год назад
I can't repeat the result. I can only get "Data Generated From Django" but no 3 items displayed.
@BekBrace
@BekBrace Год назад
do you get an error of some sort ?
@user-ep9ek4ob2t
@user-ep9ek4ob2t 10 месяцев назад
Hi..... Despite a spelling mistake, how did the program continue without an error? 'coresheaders.middleware.CorsMiddleware', in setting the correct is 'corsheaders ' .... ModuleNotFoundError: No module named 'coresheaders' !!/.
@BekBrace
@BekBrace 10 месяцев назад
Hi..... Apparently I corrected the error but didn't show the correction in the tutorial
@mogonyeget
@mogonyeget 6 месяцев назад
How to secure django rest api from post method with Postman? Because CORS doesn't work with Postman
@BekBrace
@BekBrace 6 месяцев назад
Hey , this is a great question, thanks for that! Well, the reason why CORS doesn't work with Postman is that Postman doesn't enforce CORS policies like browsers do, so If you are facing issues with CORS while testing your Django REST API using Postman, it's important to understand that Postman doesn't enforce the same-origin policy or CORS restrictions. Instead, it sends requests directly to the server without any restrictions. Here are some tips that might be able to help: 1) Authentication and Authorization: Ensure that your views are protected with proper authentication and authorization mechanisms. Django provides various authentication classes (e.g., Token-based authentication, JWT authentication) that you can use to secure your API. 2) CSRF Protection (explained in details in the tutorial): If you're using session-based authentication, make sure that CSRF protection is enabled. Simply, include the CSRF token in your requests. 3) SSL/TLS: Use HTTPS t(not HTTP) to encrypt data in transit. This is crucial for securing sensitive information. 4) Middleware Security: Consider using other security middleware provided by Django, such as django.middleware.security.SecurityMiddleware, to enable security-related headers.
@realbutnotrealgamer3334
@realbutnotrealgamer3334 Месяц назад
I'm unsure why but I've used pip3 install djangorestframework and I don't get anything named "rest_framework". Any suggestions?
@BekBrace
@BekBrace Месяц назад
pip3 for mac and Linux only. use pip only or better create a virtual environment with pipenv
@realbutnotrealgamer3334
@realbutnotrealgamer3334 Месяц назад
@@BekBrace Hey, thanks for your response. I've attempted all of the suggested instillation methods and nothing seems to be working. I'm on a mac as well I've also attempted the pipenv method and that seems to have no resolve either. Thank you in advance
@realbutnotrealgamer3334
@realbutnotrealgamer3334 Месяц назад
Disregard: I found the resolution to the issue after some time. Thank you!
@MyPodie
@MyPodie 20 дней назад
@@realbutnotrealgamer3334 would u mind sharing the solution? I'm having the same problem. Thanks in advance
@realbutnotrealgamer3334
@realbutnotrealgamer3334 20 дней назад
@@MyPodie I’m not sure if it’ll be the same for you but I ended up looking at my other python environments and remoted into the one that had the rest library. I made a major mistake in the beginning by making a ton of them so my pip3 sometimes gets confused (don’t ask me how, I was just starting out 😅) But if you have the python extension in VS Code it’ll show you all of the different environments and the libraries within them, simply set the one with your correct files as your active workspace interpreter and it’ll read those instead. Downside, you may have to re-install some things into the new active library so they’re all in one place (that’s what I did to avoid this in any future situation)
@jer9070
@jer9070 Месяц назад
How can I use it in machine learning like classification
@BekBrace
@BekBrace Месяц назад
Use Django for the backend to handle ML model predictions and serve them through an API. Use React for the frontend to collect user inputs and display predictions from the Django API.
@sridharpillai7736
@sridharpillai7736 4 месяца назад
I have one problem when i run django unlike you i dont get a html form i have to input using { "employee": "", "department": "" } this format ...... is this a browser issue or a code issue??
@BekBrace
@BekBrace 4 месяца назад
If you're not seeing a HTML form rendered in your browser when running a Django application, it's likely an issue with your code rather than a problem with your browser. Django templates should render HTML forms that users can interact with.
@grahamgideon9485
@grahamgideon9485 9 месяцев назад
How do you deploy django react on cPanel
@BekBrace
@BekBrace 9 месяцев назад
I will prepare a full tutorial on that
@sifo_io
@sifo_io 3 месяца назад
Whats your vscode theme bro ?
@BekBrace
@BekBrace 3 месяца назад
basha, wallahi mesh faker, I think it's GitHub Dark Theme
@sifo_io
@sifo_io 3 месяца назад
I was going into my ytube subscriptions and wanted to check out your channel since I haven't seen any of your videos in a while (my bad for not turning on the bell xD) Good job ya basha!@@BekBrace
@veenion2776
@veenion2776 11 месяцев назад
Please tell me your vscode font family name ?
@BekBrace
@BekBrace 11 месяцев назад
Caskadiya Cove
@pooyaarab9011
@pooyaarab9011 Год назад
hello, can you make a React crash course please ?
@BekBrace
@BekBrace Год назад
I can of course, but i have already one : React for Python backend developers. Have you seen that one ?
@pooyaarab9011
@pooyaarab9011 Год назад
@@BekBrace thank you very much , i watch it,it was perfect.
@japhethachimba174
@japhethachimba174 Год назад
Hey, thanks for the video. can you share the github link to the project.
@BekBrace
@BekBrace Год назад
I've added the link in the description, check it out
@prod-0_0
@prod-0_0 Год назад
How connect Vite with Django ?😢
@BekBrace
@BekBrace Год назад
This video discusses only React 🙂
@jpcam4781
@jpcam4781 Год назад
This works without webpack and babble?
@BekBrace
@BekBrace Год назад
No
@atikaboubia1738
@atikaboubia1738 Месяц назад
How to do that with JavaScript ( front-end) and Django ( backend) Anyone could help pls ?
@BekBrace
@BekBrace Месяц назад
I'll get back to you on this today.
Далее
Как Подключить React К Django?
17:19
Просмотров 28 тыс.
Web Developer Roadmap (2024) - Everything is Changing
25:02
FastAPI, Flask or Django - Which Should You Use?
9:49
How to use React with Django (in 10 mins) ⚛️
10:43
Просмотров 1,8 тыс.
You don't need a frontend framework
15:45
Просмотров 106 тыс.
С iPhone точно не укачает!
0:41
Просмотров 465 тыс.
#miniphone
0:16
Просмотров 3,5 млн
💅🏻Айфон vs Андроид🤮
0:20
Просмотров 684 тыс.
Неразрушаемый смартфон
1:00
Просмотров 1,6 млн