React + Django REST framework = love
Valentino Gagliardi Feb 16
I know, it's been a long time since you heard from me.
I'm a bit busy working with React and Django. Yes, Django.
"Valentino, you were supposed to talk about Node.js all the way down!"
You're right. I should talk about Node.js.
But when the client wants to see a prototype straightway it's better to use a web framework that gets things done.
And trust me, Django is great when it comes to development speed.
But how do you structure a Django project with React?
Should React mount a component for each Django template? Should React take over the routing?
Each approach has its own quirks. Here's my catch:
If you're building a SPA instead, let React manage the frontend whenever it's possible.
My sweet spot is Django REST framework for providing API endpoints. With React in its own app called "frontend".
You can find an example in my Github repo: Django REST framework + React.
How about authentication? If you want to sleep at night forget about token authentication and use the Django one instead.
You can protect the API endpoint with rest_framework permissions.
From there use the Django built-in authentication to handle user registrations and logins.
Once a user is authenticated show him the React frontend. That's all.
How about you? Are you already using Django and React?