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 中模态框中提交表单的问题

  •  
  •   llllllLllll · 2020-05-03 21:31:27 +08:00 · 2100 次点击
    这是一个创建于 1455 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我在模态框中设置了一个表单,使用 POST 提交,遇到的问题是提交后收不到表单数据,第一次在模态框中写表单,求教是哪里的问题。

    模态框代码:

        <!-- 模态框( Modal ) -->
        <form action="{{ url_for('dashboard.freeze_user') }}" method="POST">
        <div class="modal fade" id="freeze_users" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-dialog">
              <div class="modal-content">
                  <div class="modal-header">
                      <h4 class="modal-title -align-center" id="myModalLabel">确定冻结该账户?</h4>
                      </div>
                      <div class="modal-body">
    
                        <input type="username" name="user" id="user" value="" disabled="disabled">
                        <input type="submit" class="btn btn-danger" value="确认">
                        <button type="button" class="btn btn-dark" data-dismiss="modal">关闭</button>
    
                      </div>
              </div><!-- /.modal-content -->
          </div><!-- /.modal -->
        </div>
        </form>
    

    后端代码:

    @dashboard_bp.route('/api/users/freeze', methods=['POST'])
    @admins_only
    def freeze_user():
        user = request.form.get("user")
        print(request.data)
        print(user)
        # if user:
        #     print(user)
        return redirect(url_for('dashboard.users_info'))
    

    打印信息:

    127.0.0.1 - - [03/May/2020 19:29:34] "GET /usersinfo HTTP/1.1" 200 -
    127.0.0.1 - - [03/May/2020 19:29:38] "POST /api/users/freeze HTTP/1.1" 302 -
    b''
    None
    127.0.0.1 - - [03/May/2020 19:29:38] "GET /usersinfo HTTP/1.1" 200 -
    
    2 条回复    2020-05-03 21:38:05 +08:00
    fy1993
        1
    fy1993  
       2020-05-03 21:36:21 +08:00   ❤️ 1
    input 框设置为 disabled 对应的数据 是不会提交后台的
    llllllLllll
        2
    llllllLllll  
    OP
       2020-05-03 21:38:05 +08:00
    @fy1993 #1 谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3234 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 11:48 · PVG 19:48 · LAX 04:48 · JFK 07:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.