from django.contrib.auth.models import User
from piston.handler import AnonymousBaseHandler
from piston.utils import rc
class AnonymousUserHandler(AnonymousBaseHandler):
allowed_methods = ('GET', )
fields = ('id', 'username',)
def read(self, request):
try:
user = User.objects.get(username=request.GET.get('username', None))
return user
except Exception:
resp = rc.NOT_FOUND
resp.write(' User not found')
return resp
1条答案
按热度按时间q9rjltbz1#
Django-piston尊重HTTP状态码并默认处理常见错误(auth等),但您也可以使用来自piston. utils的rc抛出新的异常或状态。
例如:
查看https://django-piston-sheepdog.readthedocs.io/en/latest/helpers.html上的所有实用程序