Answer the question
In order to leave comments, you need to log in
Why does jinja return list items with quotes??
Good afternoon.
I give the jinja template an object generator containing a list of this type:
('Super post', 'helo gelo everybody', ['tag', 'tag2'])
{% for poster in post %}
<div class="blo">
<h1>{{ poster[0] }}</h1>{{ poster[1] }}
<div class="sashacom" >
{% for item in poster[2] %}
{% if item != poster[2][-1]%}
<a href="{{ url_for('tag', tag = item) }}"><b>{{ item }}</b></a>,
{% else %}
<a href="{{ url_for('tag', tag = item) }}"><b>{{ item }}</b></a>
{% endif %}
{% endfor %}
</div>
</div>
{% endfor %}
@app.route('/index/<int:page>', methods=['GET'])
def index(page):
paginate = Pagination(page)
return render_template('index.html',
paginate=paginate,
title = 'Simple blog on Flask',
post = posts.get_posts_index(page),
tag = posts.get_tags_index())
def get_posts_index(PAGE):
for posts in p.query.order_by(Post.timestamp.desc()).slice(start=POSTS_PER_PAGE*(PAGE-1),stop=POSTS_PER_PAGE*PAGE):
yield (posts.title, posts.body, posts.tag)
Answer the question
In order to leave comments, you need to log in
I had a problem that the list was treated as a string, and it was only possible to solve with [1:-1], and split(" ', ' ")
<button data-block="block-one">1</button>
<button data-block="block-two">2</button>
<button data-block="block-three">3</button>
<div class="block block-one">hello, world!!</div>
<div class="block block-two">fuck the world</div>
<div class="block block-three">fuck everything</div>
$('body').on('click', 'button', function() {
const $block = $(`.${this.dataset.block}`).toggleClass('show');
$('.block').not($block).removeClass('show');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question