【问题标题】:Invalid Syntax using @app.route使用 @app.route 的无效语法
【发布时间】:2017-10-04 23:42:16
【问题描述】:

我在第 22 行 @app.route('/start') 中得到了一个无效的语法,真的不知道为什么......我正在 Cloud9 服务器下开发它 https://c9.io ,也许有什么用它来做......我在两个虚拟环境中尝试了它,python 版本为 2.7.3 和 3.4.3。它与 hello.py 的语法完全相同,实际上确实有效......

#import random
import string
import hangman
import os
from flask import Flask, \
                request, \
                render_template, \
                url_for, \
                redirect, \
                flash


app = Flask(__name__)

@app.route('/')
@app.route('/index')
def initialize():
    WORDLIST_FILENAME = "./resources/words.txt"
    wordlist = hangman.loadWords(WORDLIST_FILENAME)
    return redirect(url_for('start_game', wordlist=wordlist)

@app.route('/start')
def start_game(wordlist):
    secretWord = hangman.chooseWord(wordlist).lower()
    hangman.hang(secretWord)
    return None

if __name__ == '__main__':
#app.debug = True
app.secret_key = 'MySecretKey'
app.run(host=os.getenv('IP', '0.0.0.0'), port=int(os.getenv('PORT',5000)))

随时与https://github.com/leomagal/hangman 合作分支此项目

【问题讨论】:

    标签: python flask


    【解决方案1】:

    缺少右括号:

    return redirect(url_for('start_game', wordlist=wordlist)
    

    如果您遇到语法错误,如果问题在错误报告的行中不明显,请查看前面的行以查找缺少括号等问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-21
      • 1970-01-01
      相关资源
      最近更新 更多