Cristina Cochior
6 years ago
7 changed files with 133 additions and 0 deletions
Binary file not shown.
@ -0,0 +1,4 @@ |
|||||
|
import os |
||||
|
|
||||
|
class Config(object): |
||||
|
SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess' |
@ -0,0 +1,11 @@ |
|||||
|
from flask_wtf import Form |
||||
|
from wtforms import TextField, IntegerField, TextAreaField, SubmitField, RadioField, SelectField, StringField |
||||
|
|
||||
|
from wtforms import validators, ValidationError |
||||
|
|
||||
|
class ReusableForm(Form): |
||||
|
name = TextField('Name:', [validators.Required('Please enter your name.')]) |
||||
|
email = TextField('Email:',[validators.Required('Please enter your email address.'), validators.Email('Please enter your email address.')]) |
||||
|
friend = RadioField('Are you a friend of De Player?', choices = [('Y','Yes'),('NY','Not Yet')]) |
||||
|
content = StringField('Description:',[validators.Required('Please enter a description.')]) |
||||
|
submit = SubmitField('Send') |
@ -0,0 +1,28 @@ |
|||||
|
from wtforms import Form, TextField, BooleanField, StringField, SubmitField, validators |
||||
|
from flask import Flask, url_for, render_template, Markup, redirect, request, flash |
||||
|
from flask import session as login_session |
||||
|
from forms import ReusableForm |
||||
|
from config import Config |
||||
|
|
||||
|
import json |
||||
|
|
||||
|
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") |
||||
|
app.config.from_object(Config) |
||||
|
|
||||
|
|
||||
|
@app.route('/', methods=['GET', 'POST']) |
||||
|
def description(): |
||||
|
form = ReusableForm(request.form) |
||||
|
print (form.errors) |
||||
|
if request.method == 'POST' and form.validate(): |
||||
|
return 'Success' |
||||
|
return render_template('description.html', form=form) |
||||
|
if __name__ == '__main__': |
||||
|
app.run(debug = True) |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,20 @@ |
|||||
|
<!doctype html> |
||||
|
<html> |
||||
|
<body> |
||||
|
<h2 style = "text-align: center;">Write something very interesting here.</h2> |
||||
|
{% for message in form.name.errors %} |
||||
|
<div>{{ message }}</div> |
||||
|
{% endfor %} |
||||
|
|
||||
|
<form method="POST" action="/write"> |
||||
|
<fieldset> |
||||
|
{{ form.hidden_tag() }} |
||||
|
<div>{{ form.name.label }} {{ form.name }}</div> |
||||
|
<div>{{ form.email.label }} {{ form.email }}</div> |
||||
|
<div>{{ form.friend.label }} {{ form.friend }}</div> |
||||
|
<div>{{ form.content.label }} {{ form.content }}</div> |
||||
|
<div>{{ form.submit }}</div> |
||||
|
</fieldset> |
||||
|
</form> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,42 @@ |
|||||
|
{% block content %} |
||||
|
<div class="formwrapper"> |
||||
|
<form method=post> |
||||
|
<div class="name"> |
||||
|
{{ form.name(placeholder='Joe Blah') }} {{ form.name.label }} |
||||
|
{% if form.name.errors %} |
||||
|
<ul class="errors">{% for error in form.name.errors %}<li>{{ error }}</li>{% endfor %}</ul> |
||||
|
{% endif %} |
||||
|
</div> |
||||
|
<div class="email"> |
||||
|
{{ form.email }} {{ form.email.label }} |
||||
|
{% if form.email.errors %} |
||||
|
<ul class="errors">{% for error in form.email.errors %}<li>{{ error }}</li>{% endfor %}</ul> |
||||
|
{% endif %} |
||||
|
</div> |
||||
|
<div class="password"> |
||||
|
{{ form.password }} {{ form.password.label }} |
||||
|
{% if form.password.errors %} |
||||
|
<ul class="errors">{% for error in form.password.errors %}<li>{{ error }}</li>{% endfor %}</ul> |
||||
|
{% endif %} |
||||
|
</div> |
||||
|
<div class="confirm"> |
||||
|
{{ form.confirm }} {{ form.confirm.label }} |
||||
|
{% if form.confirm.errors %} |
||||
|
<ul class="errors">{% for error in form.password.errors %}<li>{{ error }}</li>{% endfor %}</ul> |
||||
|
{% endif %} |
||||
|
</div> |
||||
|
<div class="website"> |
||||
|
{{ form.website(placeholder='http://example.com') }} {{ form.website.label }} |
||||
|
</div> |
||||
|
<div class="submitbutton"> |
||||
|
<input id="submit" type="submit" value="Submit"> |
||||
|
</div> |
||||
|
</form> |
||||
|
</div> |
||||
|
|
||||
|
{% for message in get_flashed_messages() %} |
||||
|
<div class="alert alert-warning"> |
||||
|
<button type="button" class="close" data-dismiss="alert">×</button> |
||||
|
{{ message }} |
||||
|
</div> |
||||
|
{% endfor %} |
@ -0,0 +1,28 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
<title>Login</title> |
||||
|
</head> |
||||
|
<body> |
||||
|
|
||||
|
{% if message %} |
||||
|
<p>{{ message }}</p> |
||||
|
{% endif %} |
||||
|
|
||||
|
<form action="" method="post"> |
||||
|
<p> |
||||
|
<label for="username">Username</label> |
||||
|
<input type="text" name="username"> |
||||
|
</p> |
||||
|
<p> |
||||
|
<label for="password">Password</label> |
||||
|
<input type="password" name="password"> |
||||
|
</p> |
||||
|
<p> |
||||
|
<input type="submit"> |
||||
|
</p> |
||||
|
</form> |
||||
|
|
||||
|
</body> |
||||
|
</html> |
Loading…
Reference in new issue