Thanks Ammar Mohammed for the quick response, After login to the website through Chrome browser, I got the response. But when I run from Postman to test API by mentioning Basic AUTH credentials of which I created user models login credentials it's giving home page html response but which I want is JSON Response. Why it's not reading credentials I mentioned there?
Thanks ~Salima On Thu, Jul 21, 2022 at 10:58 AM Ammar Mohammed <[email protected]> wrote: > Hey Salima > I guess you can use access token authentication in DRF. > But Do you recive the response without logging in? > Please explain more please > > -- > > Ammar Mohammed > +249 113075979 > On 21 Jul 2022 07:08, "Salima Begum" <[email protected]> wrote: > >> Hi all, >> >> I am trying to convert my current project(It is developed in Django) to >> DRF. So, I set up DRF into my project then I wrote an endpoint for after >> user login on the session I need to get the response when I test the >> my-reviews API. >> >> models.py >> ``` >> class customer(models.Model): >> cust_id = models.IntegerField(null="true") >> email = models.CharField(max_length=100) >> # reemail = models.CharField(max_length=100, null='true') >> password = models.CharField(max_length=500) >> repassword = models.CharField(max_length=500, null='true') >> firstname = models.CharField(max_length=225) >> lastname = models.CharField(max_length=225, null=True) >> state = models.CharField(max_length=64, null=True) >> city = models.CharField(max_length=64, null=True) >> location = models.CharField(max_length=225, null=True) >> Zip = models.CharField(max_length=64) >> mailing = models.CharField(max_length=1000) >> added_date = models.DateTimeField(editable=False) >> modified_date = models.DateTimeField(null=True, blank=True) >> last_loggedin = models.DateField() >> ``` >> views.py >> >> ``` >> @api_view(['GET']) >> def myservicereviewAPI(request): >> # If a user session is logged out it will redirect to the home page. >> if ((request.session.get('email') is None) or >> (request.session.get('email') == "")): >> # redirecting user after logged out to home page. >> return HttpResponseRedirect("/home") >> if request.method == 'GET': >> students = services_review.objects.all().order_by('-added_date') >> serializer = ServicesReviewSerializer(students, many=True) >> return Response(serializer.data) >> ``` >> urls.py >> ``` >> path('myservicereviewAPI', views.myservicereviewAPI, >> name='myservicereviewAPI'), >> ``` >> >> Results of Postman when I run 'myservicereviewAPI' >> >> After login Browser results of 'myservicereviewAPI' >> >> Please Help me to achieve this. >> >> Thanks >> ~Salima >> >> -- >> 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 [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAMSz6bk%2B73gVaO0Pfq3BfT4msHAprSwyxcCq-9BWtS-faT%3DYAA%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAMSz6bk%2B73gVaO0Pfq3BfT4msHAprSwyxcCq-9BWtS-faT%3DYAA%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAHs1H7vv1b5zYXTNAk-Pm9FU5r9wVCJjODi9Pmc6BCaykKRnuQ%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAHs1H7vv1b5zYXTNAk-Pm9FU5r9wVCJjODi9Pmc6BCaykKRnuQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMSz6b%3D6HpkhJGpr5yf64GL8fta10DgfPKsbotKNVETh_d8mPA%40mail.gmail.com.

