DEV Community

The Django Rest Custom User Model and Authentication

Tarush Nagpal on July 22, 2018

I was recently building a website for one of my clients by using the Django rest + React framework ( which is beautiful by the way ) and encounte...
Collapse
 
abhirampjayan profile image
ABHIRAM P JAYAN

it is patially working. It didn't pass any values of new feilds. check this plzzz

stackoverflow.com/questions/615595...

Collapse
 
jojipams profile image
jojipams

1) I have an existing user table called user_master. It has more than 10000 existing records which was moved from the legacy system. Instead of using django's defult user table, can I use this table?
2)Second question is can I avoid using django model for managing users. means I will insert the users directly by calling Postgresql function. I want the django login check using the same user_master table.

Collapse
 
c2d628ba98 profile image
c2d628ba98

Thanks for this nice tutorial! Can you provide some info on how to update fields on the registration serializer (CustomRegisterSerializer) so it won't display the inherited fields from the parent class in the browsable API.

Collapse
 
alexferrari88 profile image
alexferrari88

great post Tarush! would you make a post explaining how to do the same but with having the user profile as a separate model?

Collapse
 
callmetarush profile image
Tarush Nagpal

It is currently a separate model

Collapse
 
alexferrari88 profile image
alexferrari88

I'm sorry but I just see one model here:
class User(AbstractBaseUser)

Collapse
 
prabhakn profile image
Prabhakaran Karthikeyan

Hi Tarush,

   Would you show me, how to integrate react js with django ?
Collapse
 
callmetarush profile image
Tarush Nagpal

Hi! There are multiple ways to do so, In the scenario for this post I had deployed my django app as a REST API and then made POST/GET Requests from my react app to django, It's makes communications very simple and straight forward.

Collapse
 
prabhakn profile image
Prabhakaran Karthikeyan

Have you used nginx to integrate fronend and backend

Thread Thread
 
callmetarush profile image
Tarush Nagpal

I think you're a little confused, nginx is a web server which mostly helps us while we're hosting it somewhere. To "integrate" frontend and backend you just need to make POST/GO requests from the frontend to the backend

Collapse
 
eng_zabi08 profile image
Zohaib

hi Tarush i need your help with one of my Drf react project i just wanted to tweak a few things but i am not able to do that because i am a newbie to Django rest framework

Collapse
 
callmetarush profile image
Tarush Nagpal

Hey! Drop me a mail

Collapse
 
pwnchaurasia profile image
Pawan Chaurasia

Thanks for the explanation.
can you tell me how can I add an image filed in it.
I need to upload user's profile picture

Collapse
 
callmetarush profile image
Tarush Nagpal

Just check out the Django documentation, they have a great example and explanation.
docs.djangoproject.com/en/2.2/

Collapse
 
gonzaloamadio profile image
Gonzalo Amadio

You should make it clear, that you will use which library for a faster reading =)
Not bad post anyway!

Collapse
 
sebamutuku profile image
SebaMutuku

Hi Tarush,
Would you kindly assist in creating a login Serializer ,model and View for users to login with token authentication? But Custom based Models. I'm a bit stuck somewhere

Collapse
 
ekaharo profile image
Kaharo • Edited

Great Article. Thanks for sharing.
Instead of username being email address what if you wanted to use phone number ?
What other changes would one need to make ? Thanks