推荐学习书目
› 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
forreal
V2EX  ›  Python

请教个关于 flask-wtf 的问题

  •  
  •   forreal · Jul 11, 2014 · 7111 views
    This topic created in 4467 days ago, the information mentioned may be changed or developed.
    第一个是页面添加了{{ csrf_token() }},并且post给后端后,将这个token和服务器端的token比对,但是服务器端的token如何获取呢?也是csrf_token()吗?我还看到api里有一个generate_csrf()。是用generate_csr函数获取服务器端token吗?还是用api里的另一个函数validate_csrf()来验证token?

    第二个问题是 RecaptchaField是验证码吗?我试了一下没有验证码图片啊。是我理解错了吗?
    顺便求一个flask验证码的扩展。

    在此多谢各位的回答
    9 replies  •  2014-07-21 22:04:50 +08:00
    casparchen
        1
    casparchen  
       Jul 11, 2014
    session['csrf_token']
    casparchen
        2
    casparchen  
       Jul 11, 2014   ❤️ 1
    另外, 如果你用flask-WTF的话,是用不着你自己去做这个验证的吧
    forreal
        3
    forreal  
    OP
       Jul 11, 2014 via iPhone
    @casparchen 只想用csrf保护,其它表单想自己写
    xxr3376
        4
    xxr3376  
       Jul 11, 2014   ❤️ 1
    @forreal RecaptchaField是用的Google的reCaptcha服务,现在在国内很有可能被墙了所以没法用。以及你需要去reCaptcha申请一个公私钥才能用。
    bcxx
        5
    bcxx  
       Jul 12, 2014   ❤️ 1
    @forreal 那你不能直接自己实现一个 csrf 么?为啥还要用 flask-wtf(不是看中 wtforms 么?

    顺便帮你 @lepture 他是现在的维护者
    tokki
        6
    tokki  
       Jul 12, 2014   ❤️ 1
    其实wtf的作用就是高效率,如果你要自己去控制csrf,自己去做验证码,用wtf的意义已经减半了
    自己实现一个csrf也很简单,flask官方就有一个例子,自己搜下啦
    forreal
        7
    forreal  
    OP
       Jul 12, 2014 via iPhone
    @xxr3376 原来如此
    forreal
        8
    forreal  
    OP
       Jul 12, 2014 via iPhone
    @bcxx
    @tokki
    也对哈,刚接触flask,看到有个教程用的wtf。
    lepture
        9
    lepture  
       Jul 21, 2014
    csrf and forms should be together.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2231 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 05:23 · PVG 13:23 · LAX 22:23 · JFK 01:23
    ♥ Do have faith in what you're doing.