预先警告三重新手威胁 - python 新手,python anywhere 新手,flask 新手。

[pythonanywhere-root]/mysite/test01.py

# A very simple Flask Hello World app for you to get started with...

from flask import Flask
from flask import render_template # for templating
#from flask import request   # for handling requests eg form post, etc

app = Flask(__name__)
app.debug = True #bshark: turn on debugging, hopefully?

@app.route('/')
#def hello_world():
#    return 'Hello from Flask! wheee!!'
def buildOrg():
    orgname = 'ACME Inc'
    return render_template('index.html', orgname)

然后在 [pythonanywhere-root]/templates/index.html
<!doctype html>
<head><title>Test01 App</title></head>
<body>
{% if orgname %}
  <h1>Welcome to {{ orgname }} Projects!</h1>
{% else %}
<p>Aw, the orgname wasn't passed in successfully :-(</p>
{% endif %}
</body>
</html>

当我访问该网站时,我收到“未处理的异常”:-(
我如何让调试器至少吐出我应该从哪里开始寻找问题?

最佳答案

问题是 render_template 只需要一个位置参数,其余参数作为仅关键字参数传递。因此,您需要将代码更改为:

def buildOrg():
    orgname = 'ACME Inc'
    return render_template('index.html', name=orgname)

对于第一部分,您可以在 pythonanywhere.com 上的 Web 选项卡下找到错误日志。

关于pythonanywhere + flask : website just says 'unhandled exception' . 如何让调试器打印堆栈跟踪?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22670403/

10-12 21:22