python - Flask wtforms own style -
i want make registration flask:
@app.route('/register/', methods=['get','post']) def register(): form = registrationform(request.form) if request.method == 'post' , form.validate(): username = form.username.data mail = form.mail.data password = sha256_crypt.encrypt((str(form.password.data))) c, conn = dbconnect.conn() x = c.execute("select * users username = (%s)", (thwart(username))) if int(x) > 0: flash("this username taken. please choose another!") return render_template("register.html", form=form, nav=8) else: c.execute("insert users (username, password, mail, credits, settings, rank, items) values (%s, %s, %s, %s, %s, %s, %s)", thwart(username), thwart(password), thwart(mail), thwart(100), thwart(""), thwart(1), thwart("")) conn.commit() flash("you registered!") c.close() conn.close() gc.collect() session['logged_in'] = true session['username'] = username return redirect(url_for('dashboard')) return render_template("register.html", form=form, nav=8)
i'm using wtforms see. problem is, registration page is:
{% extends "default.html" %} {% block body %} <h4>register</h4> <form action="" method="post"> {% "_formhelpers.html" import render_field %} {{ render_field(form.username) }} {{ render_field(form.mail) }} {{ render_field(form.password) }} <p><input class="btn btn-primary form-control" type="submit" value="register"></p> </form> {% endblock %}
so render_field defined following:
{% macro render_field(field) %} {{ field(**kwargs)|safe }} {% endmacro %}
but textboxes default style, no placeholder , no style. i'm using bootstrap , want formated like:
<p><input type="text" class="form-control" placeholder="{{ field.label }}" name="{{ field.label }}" value=""></p>
how style them?
here how can write it
{% macro render_field(name, class='class-name', value='', type='text') -%} <input type="{{ type }}" name="{{ name }}" class="{{ class }}" value="{{ value }}"/> {%- endmacro %}
your case
{% macro render_field(name, class='form-control', type='text') %} {{ field(**kwargs | safe) }} {% endmacro %}
you can apply own style while rendering field.
Comments
Post a Comment