-1

submit an Ip to post1.py

@main.route('/post1',methods=['GET','POST'])
@login_required
def post1():
    Ip=request.form['Ip']
    print Ip
    return redirect(url_for('.post',Ip=Ip))

then redirect to post.py

@main.route('/post', methods=['GET', 'POST'])
@login_required
def post():
    #Ip=request.args['Ip']

    form = RepairForm(request.form)
    print request.form
    if request.method == "POST":

        repair = Repair(Ip=form.ip.data,Series=form.series.data,Hostname=form.hostname.data,
                ManagerIp=form.managerip.data,Comp=form.comp.data,
                Model=form.model.data,Location=form.location.data,Box=form.box.data,
                Important=form.important.data,Faultype=form.faultype.data,
                Subject=form.subject.data,Body=form.body.data,Classify=form.classify.data,
                Status=form.status.data,auth_id=current_user._get_current_object().id,
                Owner=current_user._get_current_object().username,)
        db.session.add(repair)
        db.session.commit()
        flash('报修成功')
        return redirect(url_for('.index'))

    form.ip.data=1
    print form.ip.data
    form.hostname.data=1
    print form.hostname.data
    print request.form
    form.managerip.data=1
    form.comp.data=1
    form.model.data=1
    form.location.data=1
    form.box.data=1
    form.important.data=1
    form.faultype.data=1
    form.classify.data=1
    form.status.data=1
    return render_template('post.html',form=form)

all test ok,but when I uncomment Ip=request.args['Ip'],then test returns 'The browser (or proxy) sent a request that this server could not understand',

Flasking
  • 101
  • 2
  • 11

2 Answers2

0

use request.args.get('Ip') solved this error,but do not know the reason because request.args['Ip'] still can get the data.

Flasking
  • 101
  • 2
  • 11
0

This post points out the Form sending error:

Flask raises an HTTP error when it fails to find a key in the args and form dictionaries. What Flask assumes by default is that if you are asking for a particular key and it's not there then something got left out of the request and the entire request is invalid.

You can't use request.args['Ip']because Flask use a custom dictionary implementation from werkzeug called MultiDict. It has his own get method.

Community
  • 1
  • 1
molivier
  • 2,146
  • 1
  • 18
  • 20