Form handling in Flask

Now I’m coding simple design-tracking system. Almost looks like a blog service.

I use Flask as web app flame work. But I’m not good at web design. It’s difficult for me to make form template.

There are some extensions about Flask.  And I found that using Flask-Bootstrap( Bootstrap ) make easy to beautiful layout.

Key point was that, wrap form tag with <div class=”form-group tag”> and set “form-control” class in form.field.

 

{% extends "base.html" %}
{% block content %}
<div class='content container'>
<div class="row">
<div class="col-md-12">
<p>Project Code {{ pj }}</p>
<p> DESIGN TRACKER</p>
</div>
</div>
<div class="row">
<div class="col-md-4">

<form role="form" action="/hypothesis/create/", method='post'>
<div class="form-group">
{% for field in form if field.id != "csrf_token" %}
 {{ field.label }}{{ field(class="form-control") }}
{% endfor %}
</div>
</form>
</div>

This code will make following view..
form_screenshot

Just tips for me.

Published by iwatobipen

I'm medicinal chemist in mid size of pharmaceutical company. I love chemoinfo, cording, organic synthesis, my family.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: