javascript - flask 同一页面两个form怎么处理。
怪我咯
怪我咯 2017-04-11 10:30:22
[JavaScript讨论组]

页面:

html内容:

{% for messages in get_flashed_messages() %}

{{ messages }}

{% endfor %}

WW打补丁操作


{% for server in serverlists %} {% if loop.index%10 ==0 %}
{% endif %} {% endfor %}


{{ patchform.hidden_tag() }} {{ render_field(patchform.patchcommand,class="form-control",placeholder="Patch Command") }}



服务端内容:

@ww.route('/upload',methods=['POST','GET'])
def upload():
    if request.method == 'POST':
        file = request.files['file']
        if file and allww_file(file.filename):
            upload_path = app.config['UPLOAD_FOLDER']
            if not os.path.exists(upload_path):
                os.mkdir(upload_path)
            upload_file = path.join(upload_path,secure_filename(file.filename))
            file.save(upload_file)
            flash('upload file %s complete!' %file.filename)
            return redirect(url_for('ww.upload'))
        else:
            flash('nothin file select or file type error!')
    return render_template('ww/patchww.html')


@ww.route('/Patchww',methods=['GET','POST'])
def Patchww():
    cmdpatch = None
    serverlists = wwGame.query.all()
    patchform = PatchCommandForm()
    if patchform.validate_on_submit():
        session['cmdpatch'] = patchform.patchcommand.data
        session['serverID'] = request.form.getlist('dbcheckbox')


        #判断是否选服
        if session.get('serverID') == []:
            flash(u'未选游戏服,请勾选游戏服!')
            return redirect(url_for('ww.Patchww'))

        for db in session.get('serverID'):
            dbsql = wwGame.query.filter_by(serverId=db).first()
            dbhost = dbsql.serverHost
            dbname = dbsql.serverName
            session['dbname'] = dbname
            session['dbhost'] =dbhost
            print session.get('dbhost')
        print session.get('cmdpatch')
        return redirect(url_for('ww.Patchww'))
    return render_template('ww/patchww.html',
                           serverlists=serverlists,
                           patchform=patchform,
                           )

当使用第二个form时,也就是上传文件的时候:

出现了:'patchform' is undefined
但是 patchform 是第一个form的定义内容。这为咋提交的时候会触发第一个from 的?

===================

使用ajax解决了,新问题出现了

form1,form2其实对应了两个后端的views,当form2的views上传完文件后,form1的views里要怎样获得刚刚上传的文件的文件名?
即:
@ww.route('/Patchww',methods=['GET','POST']) 要怎样取到@ww.route('/upload',methods=['POST','GET'])这里面的file.filename值?

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(1)
大家讲道理

Ajax提交到不同链接不就好了

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号