django淘宝API插件 django-taobao

码农软件 · 软件分类 · 网店系统/电子商务 · 2020-02-01 19:29:51

软件介绍

django 应用的淘宝API 插件, 实在觉得淘宝官方的不好用, 用 django-taobao插件可快速让django项目调用淘宝API

安装

pip install django-taobao

配置

目前我将淘宝授权的代码贡献到了 python social auth. 所以授权是需要安装 python_social_auth并且简单配置 django的settings.py:

INSTALLED_APPS = (
    ...
    'django_taobao',
    'django_social_auth.apps.django_app.default',
)

AUTHENTICATION_BACKENDS = [
    'social.backends.taobao.TAOBAOAuth',
]

SOCIAL_AUTH_TAOBAO_KEY = 'your client id'
SOCIAL_AUTH_TAOBAO_SECRET = 'your app secret'
      TAOBAO_API_URL ='https://gw.api.tbsandbox.com/router/rest'

把 social_auth 加入到 你的 urls.py:

url(r'^taobao/', include('taobao.urls')), # this is taobao api example
url('', include('social.apps.django_app.urls', namespace='social')), # this is for auth

现在可以到 youhost.com/login/taobao 登陆 并取到token

使用 API

有了token以后, 就可以使用API了. 代码里的 view.py其实就是个例子:

def user_info(request):
          print request.user.id
          user = get_object_or_404(UserSocialAuth.objects.filter(provider='taobao'),user=request.user)
          token = user.extra_data['access_token']
          t = TaoBao()
          t.setParams(access_token=token, method='taobao.user.seller.get')
          t.setFields('nick,sex')
          return render_to_response("taobao/index.html", RequestContext(request, {'seller':t.fetch()}))

本文地址:https://codercto.com/soft/d/24682.html

The Photoshop Anthology

The Photoshop Anthology

Corrie Haffly / SitePoint Pty. Ltd. / 2006 / USD 39.95

The Photoshop Anthology is full-color, question-and-answer book for Web Designers who want to use Photoshop to build Websites and create better looking web graphics more effectively. The book covers: ......一起来看看 《The Photoshop Anthology》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试