1

I have a list in python. Each element in a list will have a lengthy line. my code is printing all element in the list but, since every element are too lengthy its printing each element as whole continues paragraph

I need like: All the element should print one by one. since its too lengthy i can have Horizontal scroll bar. so that i can have one by one. Here's my code

index.html
<html>
<head>
    <meta charset="UTF-8">
    <title> checking</title>
</head>
<body>

      {%for i in Jinja_list %}

    {{ i }}
   
{%endfor%}
    </body>
</html>
app.py
@app.route('/',methods=['POST'])
def index():
       Jinja_list = ['lenthyyyyy line1',''lenthyyyyy line2',......]
       return render_template('index.html',Jinja_list=Jinja_list)

if __name__ == "__main__":
    app.run(debug=True, port=5042)

(i need like) output:(as soon as runs the app.py) (in the browser)

lenthyyyyy line1........
lenthyyyyy line2..........
lenthyyyyy line3......

###Since it lenghty how can i have horizontal scroll bar

0

2 Answers 2

1

First of all, you must pass a list to the view. After that you should use a for loop to iterate over the items and create elements like <tr> or <div> to show them.

I can see that you don't know how to create one of those elements. Let's say we want to put the data of each item in a <div>, you can do something like this.

{% for e in list %}
<div>
    {{e}}
</div>
{% endfor %}

if you want, you can also pass a list of some objects to send even more complex data.

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

Comments

0

In your template try to do this:

<html>
<head>
    <meta charset="UTF-8">
    <title> checking</title>
</head>
<body>

   {%for i in Jinja_list %}

      <p>{{ i }}</p>
   
   {%endfor%}
    </body>
</html>

Specifically, add the <p> tag where you want to print the value of i. This will make sure that each element from your list will get printed below the previous one (line by line).

2 Comments

i tried u r code but this time i am getting like small -small paragraph. is there any other way bro?
If you want to style your output in your browser's view, you have to look inside CSS (Cascading Style Sheets). That is the way how you can change size, color and lots of other things of your HTML output. For that, I suggest you open a new question asking specifically how to style your output with CSS, in this question you asked about Jinja2.

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.