In DjangoRestFramework(DRF), name 'request' is not defined
<p>I'm making api that gets 'android or iphone' user's coordinates, and depend on that coordinates, makes 'post_list'(It means just post_list literally).</p>

<p>Using DRF i made my queryset(this queryset is for making 'post_list') like this</p>

<p><strong>views.py</strong></p>

<pre><code>from django.shortcuts import render
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.measure import D
from .models import Post
from django.http import HttpResponse
from blog.models import Post, Comment
from blog.serializers import PostSerializer, CommentSerializer
import django_filters
from rest_framework import filters, viewsets, generics
from rest_framework.decorators import permission_classes
from rest_framework.permissions import IsAuthenticated


class PostViewSet(viewsets.ModelViewSet):
    serializer_class = PostSerializer
    permission_classes = [IsAuthenticated]

    def get_queryset(self) :
        #these are for getting user's coordinates.
        lat = request.POST.get('user_lat', '13')
        lon = request.POST.get('user_lon', '15')
        userpoint = GEOSGeometry('POINT(' + lat + ' ' + lon + ')', srid=4326)
        #these is for making my post_list
        result = []
        i = 1
        while i&lt;50:
            list_i = Post.objects.filter(point__distance_lte = (userpoint, D(km=i)))
            result.extend(list_i)
            if len(result) &gt; 0:
                result = result[:0]
                break
            i += 1
        return self.result
</code></pre>

<p><strong>error traceback</strong></p>

<pre><code>Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/posts/

Django Version: 1.9.7
Python Version: 3.5.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.gis',
 'django.contrib.sites',
 'debug_toolbar',
 'blog',
 'rest_framework',
 'rest_framework.authtoken',]

Installed Middleware:
['debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/home/keepair/djangogirls/myvenv/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/home/keepair/djangogirls/myvenv/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/keepair/djangogirls/myvenv/lib/python3.5/site-packages/django/views/decorators/csrf.py" in wrapped_view
  58.         return view_func(*args, **kwargs)

File "/home/keepair/djangogirls/myvenv/lib/python3.5/site-packages/rest_framework/viewsets.py" in view
  87.             return self.dispatch(request, *args, **kwargs)

File "/home/keepair/djangogirls/myvenv/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
  466.             response = self.handle_exception(exc)

File "/home/keepair/djangogirls/myvenv/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
  463.             response = handler(request, *args, **kwargs)

File "/home/keepair/djangogirls/myvenv/lib/python3.5/site-packages/rest_framework/mixins.py" in list
  40.         queryset = self.filter_queryset(self.get_queryset())

File "/home/keepair/djangogirls/blog/views.py" in get_queryset
  28.         lat = request.POST.get('user_lat', '13')

Exception Type: NameError at /posts/
Exception Value: name 'request' is not defined
</code></pre>

<p>I made these codes following <a href="http://www.django-rest-framework.org/tutorial/6-viewsets-and-routers/#tutorial-6-viewsets-routers" rel="nofollow">http://www.django-rest-framework.org/tutorial/6-viewsets-and-routers/#tutorial-6-viewsets-routers</a> , <a href="http://www.django-rest-framework.org/api-guide/viewsets/#api-reference" rel="nofollow">http://www.django-rest-framework.org/api-guide/viewsets/#api-reference</a></p>

<p>But i think i didn't understand fully docs at above</p>

<p>Please help me, what should i do to solve this?</p>