Z
Z
zigen2015-02-26 13:07:59
Flask
zigen, 2015-02-26 13:07:59

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'])

I'm starting to iterate this business into a template
{% 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 %}


The zero and first element are displayed normally, the elements of the list are displayed with quotes!!

Passing to the template:
@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())


I pass through the Post parameter.
Function:
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)


Someone faced similar? already brainwashed himself.
Thanks for the tips

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Rostislav Grigoriev, 2015-02-26
@crazyzubr

Most likely posts.tag is a string, not a list.

N
narnik, 2016-09-20
@narnik

I had a problem that the list was treated as a string, and it was only possible to solve with [1:-1], and split(" ', ' ")

0
0xD34F, 2017-11-19
@pi4yyy

<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');
});

G
Griboks, 2017-11-19
@Griboks

Use jQuery UI. There are a lot of such cool things at the office. site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question