Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

simple jwt django

pip install djangorestframework-simplejwt
Comment

create jwt token in django

@api_view(['POST'])
@permission_classes([AllowAny, ])
def authenticate_user(request):
 
    try:
        email = request.data['email']
        password = request.data['password']
 
        user = User.objects.get(email=email, password=password)
        if user:
            try:
                payload = jwt_payload_handler(user)
                token = jwt.encode(payload, settings.SECRET_KEY)
                user_details = {}
                user_details['name'] = "%s %s" % (
                    user.first_name, user.last_name)
                user_details['token'] = token
                user_logged_in.send(sender=user.__class__,
                                    request=request, user=user)
                return Response(user_details, status=status.HTTP_200_OK)
 
            except Exception as e:
                raise e
        else:
            res = {
                'error': 'can not authenticate with the given credentials or the account has been deactivated'}
            return Response(res, status=status.HTTP_403_FORBIDDEN)
    except KeyError:
        res = {'error': 'please provide a email and a password'}
        return Response(res)
Comment

PREVIOUS NEXT
Code Example
Python :: python cartesian product 
Python :: python diamond 
Python :: remove empty rows csv python 
Python :: take input in 2d list in python 
Python :: add background image in django uploaded file 
Python :: python tkinter set minimum window size 
Python :: how to fill missing values dataframe with mean 
Python :: python check string case insensitive 
Python :: accuracy score 
Python :: how to make random colors in python turtle 
Python :: jupyter notebook make new lines 
Python :: python program to count vowels in a string 
Python :: install qt designer python ubuntu 
Python :: initialize array of natural numbers python 
Python :: percentage of null values for every variable in dataframe 
Python :: django custom primary key field 
Python :: scientific notation matplotlib python 
Python :: flask db migrate 
Python :: python requests with login 
Python :: create 2d list dictionary 
Python :: how to make rich presence discord,py 
Python :: array as an input in python 
Python :: python live video streaming flask 
Python :: ipython play sound 
Python :: python center window 
Python :: python find specific file in directory 
Python :: python replace string in file 
Python :: tofixed in python 
Python :: how to read a text file from url in python 
Python :: modulus of python complex number 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =