I want to make a registration with flask:
@app.route('/register/', methods=['GET','POST'])
def register():
form = RegistrationForm(request.form)
if request.method == 'POST' and 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 * FROM users WHERE username = (%s)", (thwart(username)))
if int(x) > 0:
flash("This username is already taken. Please choose another!")
return render_template("register.html", form=form, nav=8)
else:
c.execute("INSERT INTO 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 are successfully 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 like you could see. The problem is, that my registration page is:
{% extends "default.html" %}
{% block body %}
<h4>Register</h4>
<form action="" method="post">
{% from "_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 the render_field is defined as following:
{% macro render_field(field) %}
{{ field(**kwargs)|safe }}
{% endmacro %}
But the textboxes are just default style, so no placeholder and no style. I'm using bootstrap and want that they are formated like:
<p><input type="text" class="form-control" placeholder="{{ field.label }}" name="{{ field.label }}" value=""></p>
How to style them?
Here is how we can write it
Your case
You can always apply the own style while rendering the field.