def home(): if request.method == "POST": word = request.form['word'].lower() if word: d = my_dictionary.define(word) if d: count = my_dictionary.update_and_get_tally(word) word = d['word'] definition = d['definition'] if count > MESSAGE_THRESHOLD: # TODO: # Maybe there should be a field to add a custom # mnemonic device? message = "It seems you are struggling to remember that word" else: message = "" else: # TODO: # Hmm, could this lead to a user injection? message = "Definition not found for '%s'" %(word) count = None word = None definition = None else: word = None definition = None count = None message = "" return render_template("site.html", word=word, definition=definition, count=count, message=message)
# mnemonic device? message = "It seems you are struggling to remember that word" else: message = "" else: # TODO: # Hmm, could this lead to a user injection? message = "Definition not found for '%s'" %(word) count = None word = None definition = None else: word = None definition = None count = None message = "" return render_template("site.html", word=word, definition=definition, count=count, message=message) if __name__ == "__main__": # Define any word, to initialize the NLTK libraries. # This takes about 3 seconds and is a first-time-only delay. # Don't report looking this word up to the database my_dictionary.define('cake') app.debug = True # Set to false if this ever gets deployed. ip = "0.0.0.0" port = 5000 app.run(ip, port)