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 :: getting tradingview historical data using python 
Python :: django custom authentication 
Python :: sorted key python 
Python :: yahoo finance python documentation 
Python :: pandas count occurrences of certain value in row 
Python :: python local variables 
Python :: Python How to convert a string to the name of a function? 
Python :: python or 
Python :: openpyxl get row from sheet 
Python :: cv2.videocapture python set frame rate 
Python :: vigenere cipher with all printable characters python 
Python :: analog of join in pathlibn 
Python :: sns boxplot ylabelsize 
Python :: dockerize django app 
Python :: required_fields = [] 
Python :: how to change padding of dbc.col 
Python :: python print exection type 
Python :: difference between awswrangler and boto3 
Python :: django form label in template 
Python :: multiple categories on distplot 
Python :: python write list to file with newlines 
Python :: seaborn boxplot (both categorical and numeric data) 
Python :: how to combine two lists in one python 
Python :: how to remove groups/user_permissions from user admin panel in django,how to edit fields shown on user admin panel 
Python :: pandas redondear un valor 
Python :: accessing values in dictionary python 
Python :: python cast number to between 0 and 1 
Python :: how to iterate through a pandas dataframe 
Python :: How can i restrict letters after a number in an input in Python 
Python :: check even or odd in single line 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =