From 15cac0116ebd4cb0f78875e15a710484cd66ef7b Mon Sep 17 00:00:00 2001 From: Cristina Cochior Date: Thu, 10 Jan 2019 17:48:42 +0100 Subject: [PATCH] first attempt at the form --- .DS_Store | Bin 0 -> 6148 bytes config.py | 4 ++++ forms.py | 11 +++++++++ newstart.py | 28 +++++++++++++++++++++++ templates/description.html | 20 +++++++++++++++++ templates/form-template.html | 42 +++++++++++++++++++++++++++++++++++ templates/login.html | 28 +++++++++++++++++++++++ 7 files changed, 133 insertions(+) create mode 100644 .DS_Store create mode 100644 config.py create mode 100644 forms.py create mode 100644 newstart.py create mode 100644 templates/description.html create mode 100644 templates/form-template.html create mode 100644 templates/login.html diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..534ff2b610557ab77d17ca5c0c54b05e3a75facf GIT binary patch literal 6148 zcmeHK%Wl&^6upy%)+Q1diAC9YM;B3*DnQv`LW)!&Bvd21piu1CZ7dm26g!Pjh?FJI zJ)eN!SNMP~_yN8moOuMrP1vFc&6Vz)>zRAzaV*bxh={cY(GHPAL>63N^)iYjCfbEB zSVh;^KqmW0=#;jpM{oAig=|w{6fg>`ngZh6wW&j#GCHBT@0WMNl!s^)Tf;;67Mx9| zD8+Vg0!E)+Q$G9NOZh*Lvo)0_^K0lmrXjKm3cxFtvDm={mQ4q=NB5~skAd45E!t1# z$6@D!0k7zJt?LmAtfW)Ut-QR@dnq@{J88(d+_h{>FUDX!N-PHmw+U z!yq`WMo;5JAzENeQGtre^c90CI_h1W=V_cMRCHqc^1<}TOy5wL93B0;GM$*G(3D02 zqd-}KHTCF-^MCK}_y01_CCkjymGd}`S22&UX{;2}L0UW%kR{#J2 literal 0 HcmV?d00001 diff --git a/config.py b/config.py new file mode 100644 index 0000000..242d1b0 --- /dev/null +++ b/config.py @@ -0,0 +1,4 @@ +import os + +class Config(object): + SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess' \ No newline at end of file diff --git a/forms.py b/forms.py new file mode 100644 index 0000000..44f290a --- /dev/null +++ b/forms.py @@ -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') \ No newline at end of file diff --git a/newstart.py b/newstart.py new file mode 100644 index 0000000..cfc63b6 --- /dev/null +++ b/newstart.py @@ -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) + + + + + + + \ No newline at end of file diff --git a/templates/description.html b/templates/description.html new file mode 100644 index 0000000..66d315d --- /dev/null +++ b/templates/description.html @@ -0,0 +1,20 @@ + + + +

Write something very interesting here.

+ {% for message in form.name.errors %} +
{{ message }}
+ {% endfor %} + +
+
+ {{ form.hidden_tag() }} +
{{ form.name.label }} {{ form.name }}
+
{{ form.email.label }} {{ form.email }}
+
{{ form.friend.label }} {{ form.friend }}
+
{{ form.content.label }} {{ form.content }}
+
{{ form.submit }}
+
+
+ + \ No newline at end of file diff --git a/templates/form-template.html b/templates/form-template.html new file mode 100644 index 0000000..5610bae --- /dev/null +++ b/templates/form-template.html @@ -0,0 +1,42 @@ +{% block content %} +
+
+
+ {{ form.name(placeholder='Joe Blah') }} {{ form.name.label }} + {% if form.name.errors %} +
    {% for error in form.name.errors %}
  • {{ error }}
  • {% endfor %}
+ {% endif %} +
+ +
+ {{ form.password }} {{ form.password.label }} + {% if form.password.errors %} +
    {% for error in form.password.errors %}
  • {{ error }}
  • {% endfor %}
+ {% endif %} +
+
+ {{ form.confirm }} {{ form.confirm.label }} + {% if form.confirm.errors %} +
    {% for error in form.password.errors %}
  • {{ error }}
  • {% endfor %}
+ {% endif %} +
+
+ {{ form.website(placeholder='http://example.com') }} {{ form.website.label }} +
+
+ +
+
+
+ +{% for message in get_flashed_messages() %} +
+ + {{ message }} +
+{% endfor %} \ No newline at end of file diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..5c73808 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,28 @@ + + + + + Login + + + + {% if message %} +

{{ message }}

+ {% endif %} + +
+

+ + +

+

+ + +

+

+ +

+
+ + + \ No newline at end of file