0

I'm trying to render a placeholder of form input on my website. I'm using Python Flask including Jinja 2. I have a list of strings in the python script and I randomly select one to render using Jinja2.

It's name is cplace (variable). But when I use this variable in Jinja2 like {{cplace}}, it doesn't render the value. It only renders '{{cplace}}'.

from flask import Flask, render_template
from flask_wtf import Form 
from wtforms import StringField
from random import choice
from wtforms.validators import InputRequired, Email, Length, AnyOf
import random
from flask_bootstrap import Bootstrap

app = Flask(__name__)
Bootstrap(app)
app.config['SECRET_KEY'] = 'iamahnaf'



random_placeholders = ['What is Minecraft?', 'Minecraft VS Roblox', 'Why PUBG sucks..', 'Python VS C++', 'Bootstrap VS Semantic']



@app.route("/")
def hello():
    cplace = str(random.choice(random_placeholders))
    print(cplace)
    return render_template('index.html', cplace = cplace)


if __name__ == "__main__":
    app.run()
{% import "bootstrap/wtf.html" as wtf %}
<!DOCTYPE html>

<html lang="en">
    <head>
        <title>Welcome to Ahnaf Zamil's Website</title>
        <meta charset="utf-8">
        <link rel="shortcut icon" href="../static/images/favicon.ico" sizes="64x64">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script type="text/javascript" src="../static/js/bootstrap.min.js"></script>

    </head>
    <body>

    <form class="form-inline my-2 my-lg-0">
      <input type="text" class="form-control" id="srch" name="search" placeholder={{cplace}}>
      <button class="hvr-radial-out" type="submit">Search</button>
    </form>

    </body>
</html>
1

1 Answer 1

4

his lack of quotes to the placeholder. Try it.

<input type="text" class="form-control" id="srch" name="search" placeholder="{{ cplace }}">
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.