Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python应用程序无法重定向到其他页面_Python_Html_Visual Studio_Flask - Fatal编程技术网

Python应用程序无法重定向到其他页面

Python应用程序无法重定向到其他页面,python,html,visual-studio,flask,Python,Html,Visual Studio,Flask,我正在尝试基于if和else语句将python中的一个页面重定向到另一个html页面。我已导入所需库(烧瓶,重定向)。我可以通过URL访问其他Html页面,但当我试图通过单击按钮呈现特定Html页面(completeapplication.Html)时,它显示错误未找到 在服务器上找不到请求的URL。如果您手动输入URL,请检查拼写并重试。我也使用了完整目录,但不起作用 下面是python代码 import flask import pickle import pandas as pd impo

我正在尝试基于if和else语句将python中的一个页面重定向到另一个html页面。我已导入所需库(烧瓶,重定向)。我可以通过URL访问其他Html页面,但当我试图通过单击按钮呈现特定Html页面(completeapplication.Html)时,它显示错误未找到 在服务器上找不到请求的URL。如果您手动输入URL,请检查拼写并重试。我也使用了完整目录,但不起作用

下面是python代码

import flask
import pickle
import pandas as pd
import numpy as np
from flask import Flask,redirect

from sklearn.preprocessing import StandardScaler


#load models at top of app to load into memory only one time
with open('models/loan_application_model_lr.pickle', 'rb') as f:
    clf_lr = pickle.load(f)


# with open('models/knn_regression.pkl', 'rb') as f:
#     knn = pickle.load(f)    
ss = StandardScaler()


genders_to_int = {'MALE':1,
                  'FEMALE':0}

married_to_int = {'YES':1,
                  'NO':0}

education_to_int = {'GRADUATED':1,
                  'NOT GRADUATED':0}

dependents_to_int = {'0':0,
                      '1':1,
                      '2':2,
                      '3+':3}

self_employment_to_int = {'YES':1,
                          'NO':0}                      

property_area_to_int = {'RURAL':0,
                        'SEMIRURAL':1, 
                        'URBAN':2}




app = flask.Flask(__name__, template_folder='templates')
@app.route('/')
def main():
    return (flask.render_template('index.html'))

@app.route('/report')
def report():
    return (flask.render_template('report.html'))

@app.route('/jointreport')
def jointreport():
    return (flask.render_template('jointreport.html'))

@app.route('/CompleteApplication')
def CompleteApplication():
    return (flask.render_template('CompleteApplication.html'))

@app.route("/Loan_Application1", methods=['GET', 'POST'])
def Loan_Application1():
    
    if flask.request.method == 'GET':
        return (flask.render_template('Loan_Application1.html'))
    
    if flask.request.method =='POST':
        
        #get input
        #gender as string
        genders_type = flask.request.form['genders_type']
        #marriage status as boolean YES: 1 , NO: 0
        marital_status = flask.request.form['marital_status']
        #Dependents: No. of people dependent on the applicant (0,1,2,3+)
        dependents = flask.request.form['dependents']
        
        #dependents = dependents_to_int[dependents.upper()]
        
        #education status as boolean Graduated, Not graduated.
        education_status = flask.request.form['education_status']
        #Self_Employed: If the applicant is self-employed or not (Yes, No)
        self_employment = flask.request.form['self_employment']
        #Applicant Income
        applicantIncome = float(flask.request.form['applicantIncome'])
        #Co-Applicant Income
        coapplicantIncome = float(flask.request.form['coapplicantIncome'])
        #loan amount as integer
        loan_amnt = float(flask.request.form['loan_amnt'])
        #term as integer: from 10 to 365 days...
        term_d = int(flask.request.form['term_d'])
        # credit_history
        credit_history = int(flask.request.form['credit_history'])
        # property are
        property_area = flask.request.form['property_area']
        #property_area = property_area_to_int[property_area.upper()]

        #create original output dict
        output_dict= dict()
        output_dict['Applicant Income'] = applicantIncome
        output_dict['Co-Applicant Income'] = coapplicantIncome
        output_dict['Loan Amount'] = loan_amnt
        output_dict['Loan Amount Term']=term_d
        output_dict['Credit History'] = credit_history
        output_dict['Gender'] = genders_type
        output_dict['Marital Status'] = marital_status
        output_dict['Education Level'] = education_status
        output_dict['No of Dependents'] = dependents
        output_dict['Self Employment'] = self_employment
        output_dict['Property Area'] = property_area
        


        x = np.zeros(21)
    
        x[0] = applicantIncome
        x[1] = coapplicantIncome
        x[2] = loan_amnt
        x[3] = term_d
        x[4] = credit_history

        print('------this is array data to predict-------')
        print('X = '+str(x))
        print('------------------------------------------')

        pred = clf_lr.predict([x])[0]
        
        if pred==1:
            res = 'Change

return redirect(flask.render_template('CompleteApplication.html'))
导入烧瓶
进口泡菜
作为pd进口熊猫
将numpy作为np导入
从烧瓶导入烧瓶,重定向
从sklearn.preprocessing导入StandardScaler
#将应用程序顶部的模型加载到内存中仅一次
开放式('models/loan\u application\u model\u lr.pickle','rb')作为f:
clf_lr=酸洗负荷(f)
#将open('models/knn_regression.pkl','rb')作为f:
#knn=酸洗负荷(f)
ss=StandardScaler()
性别:1,
“女性”:0}
已婚者_to_int={'YES':1,
“否”:0}
教育程度:1,
“未分级”:0}
依赖项\u到\u int={'0':0,
'1':1,
'2':2,
'3+':3}
自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇自雇,
“否”:0}
属性\u区域\u到\u int={'0,
“半农村”:1,
“城市”:2}
app=flask.flask(\uuuuu name\uuuuuuuuuu,template\u folder='templates'))
@应用程序路径(“/”)
def main():
返回(flask.render_模板('index.html'))
@应用程序路径(“/report”)
def报告():
返回(flask.render_模板('report.html'))
@app.route(“/jointreport”)
def jointreport():
返回(flask.render_模板('jointreport.html'))
@app.route(“/CompleteApplication”)
def CompleteApplication():
返回(flask.render_模板('CompleteApplication.html'))
@app.route(“/Loan\u Application1”,方法=['GET','POST'])
def Loan_应用程序1():
如果flask.request.method==“GET”:
返回(flask.render_模板('Loan_Application1.html'))
如果flask.request.method==“POST”:
#获取输入
#作为字符串的性别
genders\u type=flask.request.form['genders\u type']
#婚姻状态为布尔值是:1,否:0
婚姻状况=flask.request.form[“婚姻状况”]
#受抚养人:受申请人抚养的人数(0,1,2,3+)
dependents=flask.request.form['dependents']
#dependents=dependents\u to_int[dependents.upper()]
#教育状况为已毕业,未毕业。
教育状况=flask.request.form['education\u status']
#自营职业者:申请人是否自营职业(是,否)
自营职业=烧瓶.申请.表格[“自营职业”]
#申请人收入
ApplicationCome=浮子(烧瓶.请求.表格['ApplicationCome'])
#共同申请人收入
coapplicantIncome=浮动(flask.request.form['coapplicantIncome'])
#贷款金额为整数
loan\u amnt=浮动(flask.request.form['loan\u amnt'])
#整数期限:从10天到365天。。。
term_d=int(flask.request.form['term_d']))
#信用历史
credit_history=int(flask.request.form['credit_history'])
#财产是
property\u area=flask.request.form['property\u area']
#property_area=property_area_to_int[property_area.upper()]
#创建原始输出dict
输出_dict=dict()
产出[申请者收入]=申请者收入
产出目录[“共同申请人收入”]=共同申请人收入
输出指令[“贷款金额”]=贷款金额
输出指令[‘贷款金额期限]]=期限
输出记录['Credit History']=信用记录
输出dict['Gender']=性别类型
输出dict[‘婚姻状况’]=婚姻状况
输出目录[‘教育水平]]=教育状况
输出指令['受抚养人的数量]=受抚养人
输出指令[“自营职业”]=自营职业
输出目录['Property Area']=属性区域
x=np.零(21)
x[0]=应用程序已启动
x[1]=共同申请收入
x[2]=贷款金额
x[3]=项d
x[4]=信用记录
打印('----这是要预测的数组数据----)
打印('X='+str(X))
打印('--------------------------------------')
pred=clf_lr.predict([x])[0]
如果pred==1:
res='Change

返回重定向(flask.render_模板('CompleteApplication.html'))

return flask.render_模板('CompleteApplication.html')
redirect()
用于URL,例如
返回重定向('https://stackoverflow.com)

更改

返回重定向(flask.render_模板('CompleteApplication.html'))

return flask.render_模板('CompleteApplication.html')

redirect()
用于URL,例如
返回重定向('https://stackoverflow.com)

谢谢。它正在工作。谢谢。它现在正在工作。