python - How to pass arguments to included html in Flask web application -


i developing blog application in python flask. in view function form passed argument render_template calls 'index.html'. form works in index.html expected. there {% include '' %} tag places 'post.htm'. want use same form repeatedly in 'post.html'. how that? passed form index.html available included 'post.html' also? , if how identify button pressed in rendered page because both forms same? index.html file:

{% extends "base.html" %} {% block content %}   <h1>hi, {{ g.user.nickname }}!</h1>   <form action="" method="post" name="post">        {{ form.hidden_tag() }}     <table>        ..........        ..........         <tr>           <td><input type="submit" value="post!"></td>        </tr>      </table>    </form>      {% post in posts.items %}      <div class="{{ post.id }}">        <div>           {% include 'post.html' %}        </div>      </div>    {% endfor %}  {% endblock %} 

and post.html as:

<table>     ..........     ..........     <tr valign="top">         <td>{{ post.body }}</td>     </tr>     <tr>     <form action="" method="post" name="post">        {{ form.hidden_tag() }}        <table>            .........            .........             <td><input type="submit" value="post!"></td>                          </table>     </form>  </table> 

is possible use same form on both html files. there several form fields in rendered web page, how identify button pressed? index.html rendered code:

return render_template('index.html',                            title='home',                            form=form,                            posts=posts) 

to distinguish different forms, need unique key, e.g. hidden input-tag, contains id:

<input type="hidden" name="post_id" value="{{post.id}}"> 

for index-form can use generic id value "new".


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -