简体   繁体   中英

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. It's exactly the same syntax of a hello.py that actually does work...

#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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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