30 Star 112 Fork 0

Xavier-Lam / wechat-django

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
rest.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
Xavier-Lam 提交于 2019-09-03 11:19 . drf
#encoding: utf-8
from django.conf import settings
from django.shortcuts import redirect
from rest_framework import exceptions, generics, response, serializers as s
from wechat_django.models import WeChatUser
from wechat_django.oauth import (WeChatAuthenticated,
WeChatOAuthAuthentication,
WeChatOAuthViewMixin)
class UserSerializer(s.ModelSerializer):
class Meta:
model = WeChatUser
fields = ("openid", "nickname")
class TestAPIView(WeChatOAuthViewMixin, generics.RetrieveAPIView,
generics.CreateAPIView):
appname = settings.SAMPLEAPPNAME
permission_classes = (WeChatAuthenticated,)
queryset = WeChatUser.objects
serializer_class = UserSerializer
def create(self, request, *args, **kwargs):
return response.Response(request.wechat.user.nickname)
def get_object(self):
return self.request.wechat.user
def handle_exception(self, exc):
if isinstance(exc, exceptions.NotAuthenticated):
return redirect(self.request.wechat.oauth_uri)
return super(TestAPIView, self).handle_exception(exc)
Python
1
https://gitee.com/xavier-lam/django-wechat.git
git@gitee.com:xavier-lam/django-wechat.git
xavier-lam
django-wechat
wechat-django
master

搜索帮助