我正在使用flask_login登录并注销应用程序,但重定向回到上一页似乎不起作用.我使用flask.views和login_required作为需要用户登录的视图的装饰器.但是,当我尝试访问需要登录的/ path时,它会重定向到/ login而不是/ login?next =/path这意味着request.get.args("next")是None.
我在我的蓝图中使用登录需要的烧瓶视图,如下所示:
from flask import Blueprint, render_template, request, redirect, url_for
from flask.views import MethodView
from models import Post
from flask.ext.mongoengine.wtf import model_form
from flask.ext.login import login_required
posts_app = Blueprint('posts_app', __name__, template_folder='templates', static_folder='static', static_url_path='/static')
class ListView(MethodView):
decorators = [login_required]
def get(self):
posts = Post.objects.all()
print posts
return render_template('posts/list.html', posts=posts)
posts_app.add_url_rule('/', view_func=ListView.as_view('list'))
Run Code Online (Sandbox Code Playgroud)
在一个单独的蓝图中,我正在实现身份验证:
from flask import Blueprint, render_template, request, current_app, flash, redirect, url_for
from forms import LoginForm, RegisterForm, ForgotForm
from libs.User import User
from flask.ext.login import login_user, login_required, …Run Code Online (Sandbox Code Playgroud) 我有一个蓝图定义为:
auth_login = Blueprint('auth_login', __name__, template_folder='templates', static_folder='static', static_url_path='/static')
Run Code Online (Sandbox Code Playgroud)
我将其注册为:
app.register_blueprint(auth_login, url_prefix='/user')
Run Code Online (Sandbox Code Playgroud)
我有一条路线:
@auth_login.route('/<username>/')
def profile(username):
return render_template('profile/user.html',
username = username)
Run Code Online (Sandbox Code Playgroud)
使用此设置,/ user/endpoint永远不会像我一样设置加载静态文件,
"GET /user//static/css/lib/bootstrap.min.css HTTP/1.1"404 - "GET /user//static/css/lib/font-awesome/css/font-awesome.min.css HTTP/1.1"404 -
我真正想要的是查看根应用程序的静态文件夹而不是蓝图,所以我希望它请求
"GET /static/css/lib/bootstrap.min.css HTTP/1.1"200 -
是否可以通过static_folder或static_url_path配置它,以便路由将在根目录中查找静态文件,而不是相对于蓝图的安装位置?