Wir hatten eine folgende Aufgabe, wir haben versucht, Code so gut wie möglich zu schreiben. Aber wir können den Test nicht bestehen, da es anscheinend ein Problem im Code gibt. benötigen daher Hilfe, um den Code zu korrigieren. Anfrage, wenn uns jemand hier helfen kann, wird es großartig für uns sein. < /p>
from flask import Flask
## Define a flask application name 'app' below
app = Flask(__name__)
## Define below a view function 'hello', which displays the message
## "Hello World!!! I've run my first Flask application."
## The view function 'hello' should be mapped to URL '/' .
@app.route("/")
def hello():
return "Hello World!!! I've run my first Flask application."
## Define below a view function 'hello_user', which takes 'username' as an argument
## and returns the html string containing a 'h2' header "Hello "
## After displaying the hello message, the html string must also display one quote,
## randomly chosen from the provided list `quotes`
# Before displaying the quote, the html string must contain the 'h3' header 'Quote of the Day for You'
## The view function 'hello_user' should be mapped to URL '/hello//' .
## Use the below list 'quotes' in 'hello_user' function
## quotes = [
## "Only two things are infinite, the universe and human stupidity, and I am not sure about the former.",
## "Give me six hours to chop down a tree and I will spend the first four sharpening the axe.",
## "Tell me and I forget. Teach me and I remember. Involve me and I learn.",
## "Listen to many, speak to a few.",
## "Only when the tide goes out do you discover who has been swimming naked."
## ]
@app.route("/hello//")
def hello_user(username):
return "Hello " + username + "Quote of the Day for You"
## Define below a view function 'display_quotes', which returns an html string
## that displays all the quotes present in 'quotes' list in a unordered list.
## Before displaying 'quotes' as an unordered list, the html string must also include a 'h1' header "Famous Quotes".
## The view function 'display_quotes' should be mapped to URL '/quotes/' .
## Use the below list 'quotes' in 'display_quotes' function
## quotes = [
## "Only two things are infinite, the universe and human stupidity, and I am not sure about the former.",
## "Give me six hours to chop down a tree and I will spend the first four sharpening the axe.",
## "Tell me and I forget. Teach me and I remember. Involve me and I learn.",
## "Listen to many, speak to a few.",
## "Only when the tide goes out do you discover who has been swimming naked."
## ]
@app.route("/quotes/")
def display_quotes():
return render_template( 'test.html',name=display_quotes)
quotes = [ "Only two things are infinite, the universe and human stupidity, and I am not sure about the former.",
"Give me six hours to chop down a tree and I will spend the first four sharpening the axe.",
"Tell me and I forget. Teach me and I remember. Involve me and I learn.",
"Listen to many, speak to a few.",
"Only when the tide goes out do you discover who has been swimming naked."]
randomNumber = randint(0,len(quotes)-1)
quote = quotes[randomNumber]
## Write the required code below which runs flask applictaion 'app' defined above
## on host 0.0.0.0 and port 8000
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
< /code>
Bitte teilen Sie uns mit, wo im Fehler darin und helfen Sie uns bei der Korrektur von Code und bestehen den erforderlichen Test. < /P.>
Benötigen Sie Hilfe im Code zum Schreiben von Ansichtsfunktionen in Flask - Python Web Framework ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post