我正在尝试做一个蒸汽瓶响应以获得用户的朋友和游戏
我一直收到GET / HTTP/1.1
404错误。
有关如何修复的建议吗? 另外,我怎样才能获得json响应而不是烧瓶?
from flask import Flask, jsonify
from steamapi import core, user
app = Flask("Steamer")
core.APIConnection(api_key="apikeygoeshere")
@app.route('/user/<name>')
def hello(name=None):
try:
try:
steam_user = user.SteamUser(userid=int(useridgoeshere))
except ValueError:
steam_user = user.SteamUser(userurl=usernamegoeshere)
name = steam_user.name
content = "Your real name is {0}. You have {1} friends and {2} games.".format(steam_user.real_name,
len(steam_user.friends),
len(steam_user.games))
img = steam_user.avatar
return jsonify('hello.html', name=name, content=content, img=img)
except Exception as ex:
return jsonify('hello.html', name=name)
if __name__ == '__main__':
app.run()
不确定这是否会对错误产生任何影响,但hello.html代码如下:
<!doctype html>
<html>
<body>
<title>Hello there!</title>
{% if name %}
<h1>Hello {% if img %}<img src="{{ img }}" /> {% endif %}{{ name }}!</h1>
{% else %}
<h1>Hello Anonymous!</h1>
{% endif %}
{% if content %}
<p>{{ content }}</p>
{% endif %}
</body>
</html>
我得到的回应:
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [01/Dec/2016 17:26:08] "GET / HTTP/1.1" 404 -