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
llllllLllll
V2EX  ›  Python

问一个 flask-wtf 的问题

  •  
  •   llllllLllll · 2018-10-23 21:51:32 +08:00 · 1666 次点击
    这是一个创建于 1983 天前的主题,其中的信息可能已经有所发展或是发生改变。
    flask-wtf 可以防御 csrf,通过校验 csrf_token 实现的。请问 validate_on_submit 函数的功能应该会校验表单提交的数据同时校验 csrf_token 吧,如果是的话能否告知一下在哪部分源码实现的。感谢大佬。
    6 条回复    2018-10-29 17:35:22 +08:00
    rogwan
        1
    rogwan  
       2018-10-23 22:01:20 +08:00
    看看是不是这个地方:.../flask_wtf/csrf.py

    class CSRFProtect(object):
    ...
    leconio
        2
    leconio  
       2018-10-23 22:53:40 +08:00 via Android
    战斗砖块剧场(≧ω≦)/
    frostming
        3
    frostming  
       2018-10-24 09:26:20 +08:00   ❤️ 1
    https://github.com/lepture/flask-wtf/blob/master/flask_wtf/csrf.py#L144

    validate_csrf_token 函数会 validate 名叫 csrf_token 的 Field

    CSRFProtect 类是全站保护,上面的只是表单保护
    llllllLllll
        4
    llllllLllll  
    OP
       2018-10-24 18:27:53 +08:00
    @frostming thx !
    llllllLllll
        5
    llllllLllll  
    OP
       2018-10-26 00:11:12 +08:00
    @frostming 请问在处理一个请求时在哪里使用了 validate_csrf_token 函数来验证 csrf_token,thx。
    frostming
        6
    frostming  
       2018-10-29 17:35:22 +08:00
    @llllllLllll 你调 form.validate()或 form.validate_on_submit()的时候
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1022 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 19:33 · PVG 03:33 · LAX 12:33 · JFK 15:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.