0

app.py

from flask import Flask, render_template
import random

app = Flask(__name__)


@app.route("/")
def index():
    number = random.randint(0, 10)
    return render_template("index.html", value='number')

templates/index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Random Number</title>
</head>

<body>
    Your random number is {{ value }}.
</body>

</html>

Webpage Result

Your random number is number.

It isnt replacing the number with actual number. Kindly help!

BTW i am coding this in PyCharm

0

1 Answer 1

1

Replace

return render_template("index.html", value='number')

with

return render_template("index.html", value=number)

You need to send variable not string. If you use value='number', value is a string which is 'number' or anything inside the quotes. For example if you set value='another number', then you will see 'Your random number is another number.'

If you want to use the value of 'number' variable use it without quotes. This will ensure you are passing the value of the number variable and not a string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.