REST REQUEST没有返回正确的响应

时间:2015-05-14 20:33:53

标签: django rest django-rest-framework python-requests django-filter

我是REST的新手,并且一直致力于使用Requests(Python),Django和Django Rest Framework。我正在尝试发出一个get请求,它返回所有具有" priority"的对象。 (Int字段)值为4.问题是查询似乎没有工作,GET请求正在返回所有项目对象。结构看起来正确,我可以使用完全相同的语法更改页面,因此我不确定我做错了什么。这是我认为你需要的一切,任何帮助都会很棒。谢谢!

生成的网址= http://127.0.0.1:8000/api/projects/?priority=4

RestConnect.py {

local = 'http://localhost/'
base = 'http://127.0.0.1:8000/api/'


def sign_in(current_user, username, password):
        response = current_user.get(base + 'api-auth/login/', auth=(username, password))
        print response
        print response.url
        print response.reason

# Some of this is intentionally generic and a little rough (the way the session is being passed)
def find_priority(current_user, username, password):
    find_projects = {"priority": "4"}
    response = current_user.get(base + 'projects', params=find_projects,  auth=(username, password))
    print response
    print response.url
    print response.text

}

QueryTest.py {

import requests

import restconnect


current_user = requests.Session()

restconnect.sign_in(current_user, 'user', 'password')
restconnect.find_priority(current_user, 'user', 'password')

}

serializer.py {

from rest_framework import serializers, viewsets
import django_filters

from . models import Project


class ProjectFilter(django_filters.FilterSet):
    class Meta:
        model = Project
        fields = ['name', 'status', 'priority']


class ProjectSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Project


class ProjectViewSet(viewsets.ModelViewSet):
    queryset = Project.objects.all()
    serializer_class = ProjectSerializer
    filter_class = ProjectFilter

}

0 个答案:

没有答案