-2
第22行@ app.route('/ start')中出現無效語法,真的不知道爲什麼......我在Cloud9服務器下開發它https://c9.io ,也許這跟它有點關係......我用Python 2.7.3和3.4.3版本在兩個虛擬環境中嘗試了它。這正是它實際工作的一個hello.py的相同的語法...使用@ app.route的無效語法
#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)))
隨意colaborate分支這個項目在https://github.com/leomagal/hangman