I need to do a GET request to my Django server through an android application. The problem is that this GET function is written in Django with a @login_required.
What kind of request should i do to login and perform the GET request?
My API:
from django.shortcuts import render
from django.http import HttpResponse,HttpResponseServerError, HttpResponseBadRequest
from rest_framework.decorators import api_view
from .models import Order, New
import json
from django.shortcuts import render_to_response
from .forms import NewForm
from django.core.files.storage import FileSystemStorage
from django.contrib.auth.decorators import login_required
from .validation import *
from django.views.decorators.csrf import csrf_exempt
@login_required
@api_view(['GET'])
def get_order(request):
order_list = Order.objects.values("user_name",
"user_surname",
"order_date").all()
return HttpResponse(json.dumps([x for x in order_list])
My urls.py:
from django.urls import path
from django.conf.urls import url
from . import views
app_name = 'API'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^order', views.order, name='order'),
url(r'^get_order', views.get_order, name='get_order')]
and:
from django.contrib import admin
from . import settings
from django.views.static import serve
from django.urls import path, include, re_path
from django.conf.urls.static import static
from API.views import index
urlpatterns = [
path('API/', include('API.urls',namespace="API")),
path('admin/', admin.site.urls),
path('', index, name='index'),
path(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT})
]
In Postman i'm performing a GET (http://127.0.0.1:8000/API/get_order) with basic auth, receiving 302 status code.

TokenAuthentication. If you don't want to build RESTFul API, you need to leverage theWebViewto access your django website instead.