2016-08-12 10 views
0

結果を返すときにsqlalchemyを使用してデータベースにクエリーを実行します。結果は返されますが、結果は返されません。クエリーが返された場合にフォームに記入する方法なし

エラー

AttributeError: 'NoneType' object has no attribute 'Ip' 

コード

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

    caseid=Masterlist.query.filter_by(Ip=request.args.get('Ip')).first() 
    form = RepairForm(request.form) 
    print request.form 
    if request.form.get("submit"): 
     repair = Repair(Ip=form.ip.data,Series=form.series.data,Hostname=form.hostname.data, 
       ManagerIp=form.managerip.data,Comp=form.comp.data,Discription=form.discription.data, 
       Model=form.model.data,Location=form.location.data,Box=form.box.data, 
       Important=form.important.data,Faultype=form.faultype.data,Source=form.source.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=caseid.Ip 
    form.hostname.data=caseid.Hostname 
    form.managerip.data=caseid.Managerip 
    form.comp.data=caseid.Comp 
    form.model.data=caseid.Model 
    form.location.data=caseid.Location 
    form.box.data=caseid.Box 
    form.classify.data=caseid.Classify 
    form.series.data=caseid.Series 
    form.discription.data=caseid.Discription 

    return render_template('post.html',form=form) 
+0

'try'ブロックを使うか、' caseid: 'をチェックしますか? – Julien

答えて

0

あなたはこのためであれば、簡単な条件を使用することができます。..

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

    caseid=Masterlist.query.filter_by(Ip=request.args.get('Ip')).first() 
    if caseid: 
     form = RepairForm(request.form) 
     print request.form 
     if request.form.get("submit"): 
      repair = Repair(Ip=form.ip.data,Series=form.series.data,Hostname=form.hostname.data, 
       ManagerIp=form.managerip.data,Comp=form.comp.data,Discription=form.discription.data, 
       Model=form.model.data,Location=form.location.data,Box=form.box.data, 
       Important=form.important.data,Faultype=form.faultype.data,Source=form.source.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=caseid.Ip 
     form.hostname.data=caseid.Hostname 
     form.managerip.data=caseid.Managerip 
     form.comp.data=caseid.Comp 
     form.model.data=caseid.Model 
     form.location.data=caseid.Location 
     form.box.data=caseid.Box 
     form.classify.data=caseid.Classify 
     form.series.data=caseid.Series 
     form.discription.data=caseid.Discription 

     return render_template('post.html',form=form) 
    else: 
     pass 
+0

これはValueErrorを示しています:View関数は応答を返しませんでした。結果が返っていなければ、手動で入力する必要があります。 – Flasking

0

ここソリューション笑

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

    caseid=Masterlist.query.filter_by(Ip=request.args.get('Ip')).first() 
    form = RepairForm(request.form) 
    if caseid: 

     print request.form 
# print request.form 
# if form.validate_on_submit(): 
# if request.method == "POST": 
# if request.form["submit"] == "submitpost": 
# if request.form.get("submit", "submit"): 
     if request.form.get("submit"): 
      repair = Repair(Ip=form.ip.data,Series=form.series.data,Hostname=form.hostname.data, 
        ManagerIp=form.managerip.data,Comp=form.comp.data,Discription=form.discription.data, 
        Model=form.model.data,Location=form.location.data,Box=form.box.data, 
        Important=form.important.data,Faultype=form.faultype.data,Source=form.source.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=caseid.Ip 
     form.hostname.data=caseid.Hostname 
     form.managerip.data=caseid.Managerip 
     form.comp.data=caseid.Comp 
     form.model.data=caseid.Model 
     form.location.data=caseid.Location 
     form.box.data=caseid.Box 
     form.classify.data=caseid.Classify 
     form.series.data=caseid.Series 
     form.discription.data=caseid.Discription 

     return render_template('post.html',form=form) 
    else: 
     if request.form.get("submit"): 
      repair = Repair(Ip=form.ip.data,Series=form.series.data,Hostname=form.hostname.data, 
        ManagerIp=form.managerip.data,Comp=form.comp.data,Discription=form.discription.data, 
        Model=form.model.data,Location=form.location.data,Box=form.box.data, 
        Important=form.important.data,Faultype=form.faultype.data,Source=form.source.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')) 
     return render_template('postmanual.html') 
関連する問題