Difference between revisions of "Register and Edit profile in a Flask App"
(→Create sign up form) |
(→Create sign up template) |
||
Line 14: | Line 14: | ||
=Create sign up template= | =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: | ||
+ | |||
+ | <syntaxhighlight lang=html> | ||
+ | {% 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(size=32) }} | ||
+ | </p> | ||
+ | <p>{{ form.submit() }}</p> | ||
+ | </form> | ||
+ | {% endblock %} | ||
+ | </syntaxhighlight> | ||
=Create sign up route= | =Create sign up route= | ||
=Insert data into users table= | =Insert data into users table= |
Revision as of 22:10, 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(u'Gender', choices=['M', 'F'])
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(size=32) }}
</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}