# 验证码
@index_blue.route('/getimage')
def get_image():
# name, text, StringIO.value
# text : 验证码图片对应到到文本
# image_url : 验证码图片IO流。理解为:二进制数据,并没有实际转换成图片呢
name, text, image_url = captcha.generate_captcha()
session['img_code'] = text
response = make_response(image_url)# 生成图片到响应
# 告诉浏览器,我要返回到是一张图片
response.headers['Content-Type'] ='image/jpg'
return response
# 上传图片
@index_blue.route('/upload',methods=['GET','POST'])
def upload():
if request.method =='POST':
image = request.files.get('pic')
if image:
image_name = photos.save(image)# 将头像保存到 程序目录下
image_url ='/static/upload/' + image_name# 生成图片保存到地址
n = News()
n.title ='图片上传'
n.content = image_url
db.session.add(n)
db.session.commit()
return render_template('图片上传.html')
{{ data.content | safe}}