CGI Apache Flask应用程序,除app.route('/')

时间:2019-02-27 16:34:12

标签: python apache flask cgi

我正在尝试使用CGI,Apache和Flask创建一个网页。目前,我可以正常访问app.route('/')下的主页。我的代码中还有app.route('/ output')下的另一个函数output()。但是,当我尝试通过仅键入URL或使用HTML页面上的按钮的重定向来访问此功能时,出现错误消息:“此页面不起作用[服务器网站]没有发送任何数据。ERR_EMPTY_RESPONSE”。无论我如何尝试,我都无法弄清楚如何使用此功能。我的代码如下:

myapp.py:

from main import main
from output import toHTML
from flask import Flask
from flask import request, render_template
from inputPuzzle import inputPuzzle
from model_pylist import model


app = Flask(__name__)
app.config["DEBUG"] = True
model = model()

@app.route('/', methods = ['GET', 'POST'])
def hello_world():
    errors = ""
    if request.method == "POST":
        puzzle1 = None
        try:
            puzzle1 = str(request.form["puzzle1"])
            puzType = str(request.form["type"])
        except:
            errors += "<p>{!r} is not a valid input.</p>\n".format(request.form["puzzle1"])
        if puzzle1 is not None:
            puzType="synonym"
            aClues, dClues, puzzle = inputPuzzle(puzzle1)
            model.insert(puzzle,puzType, puzzle1)
            if aClues == "nothing":
               return '''
               <h4>You didn't enter anything to process...</h4>
               <p><a href=\"https://web.cecs.pdx.edu/~esceeles/\">Click here to do another one</a></div></p>
               '''
                if aClues == "notNum":
               return ''' 
               <h4> Please enter an integer dimension as your first element. </h4>
               <p><a href=\"https://web.cecs.pdx.edu/~esceeles/\">Click here to do another one</a></div></p>
               '''
            puzHTML, strPuzzle = toHTML(puzzle, "Does this look correct?", puzzle1, aClues, dClues, puzType)
            output()

            return puzHTML
            c = model.select()
            puzzle1 = c[0][2]
            puzType = c[0][1]
            result, trash = main(puzzle1, puzType)

            #check = main(puzzle1)
            #return check.format(puzzle1=puzzle1)

    return render_template('enterPuzzlePage.html', errors=errors)


@app.route('/output/', methods=['POST'])
def output():
    return "You made it!"
    c = model.select()
    puzzle1 = c[0][2]
    puzType = c[0][1]
    result, trash = main(puzzle1, puzType)
    return result

.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ /u/esceeles/public_html/myapp.cgi/$1 [L] 

myapp.cgi:

#!/usr/bin/python

from wsgiref.handlers import CGIHandler
from myapp import app 
CGIHandler().run(app)

我在单独的html文件中也有一个按钮,该按钮也应链接到output()函数:

<form action=\"/output/\" method=\"post\"><input type=\"submit\" value= \"Looks good!\"  name=\"button\" id=\"name\" /> </form>"

当我在本地运行此应用程序时,它工作正常,但在服务器上,出现上述错误。我该如何解决这个问题?

0 个答案:

没有答案