V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
1989922yan
V2EX  ›  Python

能给一个 flask-login 的完整例子嘛?已经折腾了一下午

  •  
  •   1989922yan · 2015-03-02 18:44:18 +08:00 · 6812 次点击
    这是一个创建于 3335 天前的主题,其中的信息可能已经有所发展或是发生改变。
    查了不少文档,没弄懂,难道是没有抓住插件开发的技巧?
    先谢过。
    7 条回复    2015-03-04 13:34:14 +08:00
    Melodic
        1
    Melodic  
       2015-03-02 18:53:19 +08:00
    没太明白你想怎么开发,是重写flask-login吗?

    我暂时只用到了 下面几个函数
    current_user, login_user, login_required, logout_user

    配合form和数据库,获取/变更用户信息,注册之类的。
    Mirana
        3
    Mirana  
       2015-03-02 20:17:15 +08:00
    自己写不行吗
    iwillhappy1314
        4
    iwillhappy1314  
       2015-03-03 02:02:44 +08:00
    为啥不直接用Flask-Security?
    gully
        5
    gully  
       2015-03-03 09:00:47 +08:00
    fork3rt
        6
    fork3rt  
       2015-03-04 11:29:49 +08:00
    @app.route("/login", methods=["GET", "POST"])
    def login():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
    req = form.validate_login()
    if req['state_code'] == 0:
    login_user(req['data'])
    else:
    flash(req['message'])
    return redirect('/login')
    return redirect(request.args.get("next") or url_for("/"))
    return render_template("user/login.html", form=form)
    firldlove
        7
    firldlove  
       2015-03-04 13:34:14 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1356 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 23:41 · PVG 07:41 · LAX 16:41 · JFK 19:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.