Difference between revisions of "Register and Edit profile in a Flask App"
(→Create sign up form) |
(→Create sign up form) |
||
Line 9: | Line 9: | ||
email = StringField('Email', validators=[]) | email = StringField('Email', validators=[]) | ||
DOB = DateField('DOB', format='%Y-%m-%d') | DOB = DateField('DOB', format='%Y-%m-%d') | ||
− | MF = SelectField( | + | MF = SelectField('Gender', choices=[('M','Male'), ('F','Female')]) |
submit = SubmitField('Sign In') | submit = SubmitField('Sign In') | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 22:36, 26 October 2019
Contents
Create sign up form
In your 'forms.py' file we need to create a form for the sign-up process. You should have created 'forms.py' when you created your login form. So add the following:
class SignUpForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
confirm = PasswordField('Confirm Password', validators=[DataRequired()])
email = StringField('Email', validators=[])
DOB = DateField('DOB', format='%Y-%m-%d')
MF = SelectField('Gender', choices=[('M','Male'), ('F','Female')])
submit = SubmitField('Sign In')
Create sign up template
My WebApp was created using Visual Studio, and it already created a 'layout' template and then separate 'html' files for each page. If you already have templates set up you should copy one of the 'html' files for a page and edit it to this:
{% extends "layout.html" %}
{% block content %}
<h1>Sign In</h1>
<form action="" method="post" novalidate>
{{ form.hidden_tag() }}
<p>
{{ form.username.label }}<br>
{{ form.username(size=32) }}
</p>
<p>
{{ form.password.label }}<br>
{{ form.password(size=32) }}
</p>
<p>
{{ form.confirm.label }}<br>
{{ form.confirm(size=32) }}
</p>
<p>
{{ form.email.label }}<br>
{{ form.email(size=32) }}
</p>
<p>
{{ form.DOB.label }}<br>
{{ form.DOB(size=32) }}
</p>
<p>
{{ form.MF.label }}<br>
{{ form.MF() }}
</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}