Refer the docs
On Thu, Apr 8, 2021 at 6:44 PM RANGA BHARATH JINKA <bharathjinka09@gmail.com> wrote:
Hi, You have to specify the POST method in the commandhttp -a USERNAME POST https://api.github.com/repos/httpie/httpie/issues/83/comments body='HTTPie is awesome! :heart:'All the bestOn Thu, Apr 8, 2021 at 6:18 PM 'Amitesh Sahay' via Django users <django-users@googlegroups.com> wrote:--HI,I have created a simple login API through django rest framework. Below is the code snippet:from django.contrib.auth import login
from rest_framework.generics import ListCreateAPIView
from rest_framework import status
from rest_framework.response import Response
from rest_framework.authtoken.serializers import AuthTokenSerializer
from rest_framework.permissions import IsAuthenticated, IsAdminUser, AllowAny
from knox.views import LoginView as KLView
from knox.models import AuthToken
from .serializers import RegistrationSerializers
from .models import NewEmployeeProfileclass loginAPIView(KLView):
permission_classes = [AllowAny]
def post(self, request, format=None):
serializer = AuthTokenSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = serializer.validated_data['user']
login(request, user)
return super(loginAPIView, self).post(request, format=None)urlpatterns = [ path('register/', UserRegisterView.as_view(), name='register'), path('login/', loginAPIView.as_view(), name='login'), ]URLS.pyfrom django.urls import pathfrom knox import views as knox_viewsfrom .views import UserRegisterView, loginAPIViewurlpatterns = [path('register/', UserRegisterView.as_view(), name='register'),path('login/', loginAPIView.as_view(), name='login'),]Now when I do a POST request in postman with the email and the password. It throws error:{"detail": "Invalid token."}Note:: Since I am using knox to generate token. So, when I do a new registration I get token as well. See sample below:{"status": "OK","message": {"email": "test.test@test.com","first_name": "est","last_name": "Sah","employee_code": "6124368","contact": "7500078619","dob": null},"token": "db058f23ecc70f4fa3de4ac69a04dc48bb7579a63aea1ad3d038ce59b1511890"I tried both, password and token to authenticate, but I am getting the same error. In the cmd prompt where the dev server is running, I am seeing below message========================[08/Apr/2021 15:26:33] "POST /apii/login/ HTTP/1.1" 403 27Forbidden: /apii/login/========================In the postman raw body, I am inserting below json data{"email": "test.test@test.com","password": "db058f23ecc70f4fa3de4ac69a04dc48bb7579a63aea1ad3d038ce59b1511890"}Below is the settings.py content for DRFREST_FRAMEWORK = {'DEFAULT_AUTHENTICATION_CLASSES': [#'rest_framework.authentication.TokenAuthentication','rest_framework.authentication.SessionAuthentication','knox.auth.TokenAuthentication',],}httpie outputpython.exe -m httpie 127.0.0.1:8000/apii/login/ 'Authorization: Token db058f23ecc70f4fa3de4ac69a04dc48bb7579a63aea1ad3d038ce59b1511890'HTTP/1.1 405 Method Not AllowedAllow: POST, OPTIONSContent-Length: 40Content-Type: application/jsonDate: Thu, 08 Apr 2021 11:52:31 GMTReferrer-Policy: same-originServer: WSGIServer/0.2 CPython/3.6.8Vary: Accept, CookieX-Content-Type-Options: nosniffX-Frame-Options: DENY{"detail": "Method \"GET\" not allowed."}Not sure if I am doing it the right way, please suggest. Thank you....
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2028966691.640551.1617886057684%40mail.yahoo.com.
--Thanks and RegardsJ. Ranga Bharathcell: 9110334114
Thanks and Regards
J. Ranga Bharath
cell: 9110334114
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK5m314UV5z%3D%3DOO-BhQFGZ9cMrnTo5ZMmYRtMmDOZsWfU7eBJA%40mail.gmail.com.
No comments:
Post a Comment