首先要在python 中安装qiniu
使用 pycharm可以很方便的安装,打开project interpreter,然后搜索即可
# coding: utf-8
from django.shortcuts import redirect, render, HttpResponse
import json
import os
import uuid
from blog import models
import qiniu
import logging
# 七牛云上传图片配置
access_key = 'xxxx'
secret_key = 'xxxx'
bucket_name = 'store1' #填你的bucket名
remote_url_prefix = 'xxxx' # 用于拼接img网址
def upload(reqeust):
'''
将文件进行上传
:param reqeust:
:return: 返回wang editor所要求的数据
'''
image = reqeust.FILES.get('image', None)
img_url = qiniu_upload(image)
print(img_url)
result = {"errno": 0, 'data': [img_url, ]} # 给wang editor返回的参数
return HttpResponse(json.dumps(result))
def qiniu_upload(file):
"""
使用七牛云
:param file:
:return:
"""
binary_file = file.rea