简体   繁体   English

使用@app.route 的无效语法

[英]Invalid Syntax using @app.route

I'm getting a Invalid Syntax in line 22 @app.route('/start') and really don't know why... I'm developing it under a Cloud9 server https://c9.io , maybe that has something to do with it... I tried it in two virtual enviroments with python versions 2.7.3 and 3.4.3.我在第 22 行 @app.route('/start') 得到一个无效的语法,真的不知道为什么......我正在 Cloud9 服务器https://c9.io下开发它,也许有与它有关......我在python版本2.7.3和3.4.3的两个虚拟环境中尝试了它。 It's exactly the same syntax of a hello.py that actually does work...它与实际工作的 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)))

feel free to colaborate branching this project at https://github.com/leomagal/hangman随时在https://github.com/leomagal/hangman 上合作分支这个项目

Missing a closing parenthesis on:缺少右括号:

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

If you get a syntax error, if the problem isn't obvious in the line the error reports, look at previous lines for issues like missing parenthesis.如果您遇到语法错误,如果问题在错误报告的行中不明显,请查看前面的行以查找缺少括号等问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM