所以我创建了一个bluiprint并用@login_required装饰。 Auth,用户等在我的主要views.py上。如果我删除@login_required我的代码工作。但如果我添加,我将被重定向到登录页面。在将代码移动到蓝图之前,Auth确实可以工作。那么如何将我的蓝图导入到auth所需的对象中?
这是我的蓝图
from flask import Flask, render_template,request,jsonify,Response
from flask import make_response,session,redirect,url_for,g
from flask.ext.security import Security
from flask.ext.login import login_user, logout_user, current_user, login_required, UserMixin,confirm_login,fresh_login_required
from flask_security import auth_token_required, http_auth_required
from passlib.apps import custom_app_context as pwd_context
from flask.ext.httpauth import HTTPBasicAuth # sudo pip install flask-httpauth
from flask import Blueprint
auth = HTTPBasicAuth()
delstack = Blueprint('/delstack/<stack_id>', __name__)
@delstack.route('/delstack/<stack_id>', methods=['DELETE'])
@login_required
def delstack_route(stack_id):
jd = {'status':'ok'}
data = json.dumps(jd)
resp = Response(data, status=200, mimetype='application/json')
return resp