Added requirements for the project, added WTForms for contact form validation, and finished setting up the contact form. Now ready to go into production for testing there.
This commit is contained in:
parent
a13ca0a81b
commit
1e155009f6
6 changed files with 50 additions and 13 deletions
|
@ -1,8 +1,9 @@
|
||||||
MYSQL_USER = 'user'
|
MYSQL_USER = 'user'
|
||||||
MYSQL_PASSWORD = 'password'
|
MYSQL_PASSWORD = 'password'
|
||||||
MYSQL_HOST = 'localhost'
|
MYSQL_HOST = '%'
|
||||||
MYSQL_DB = 'database'
|
MYSQL_DB = 'database'
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
SECRET_KEY = 'development key'
|
SECRET_KEY = '\xd9\n\xe6[Hy\xf6\xac\x00\xd3b\xc2\xb3\x98Ii\x8e\x1b\xcb\xcc\x89'K\x1f'
|
||||||
USERNAME = 'username'
|
USERNAME = 'username'
|
||||||
PASSWORD = 'password'
|
PASSWORD = 'password'
|
||||||
|
MAIL_DEFAULT_SENDER = "admin@example.com"
|
|
@ -5,6 +5,7 @@ import hashlib
|
||||||
from flask_debugtoolbar import DebugToolbarExtension
|
from flask_debugtoolbar import DebugToolbarExtension
|
||||||
from admin import admin
|
from admin import admin
|
||||||
from flask.ext.mail import Mail, Message
|
from flask.ext.mail import Mail, Message
|
||||||
|
from wtforms import Form, TextField, TextAreaField, validators
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_pyfile('config.py')
|
app.config.from_pyfile('config.py')
|
||||||
|
@ -28,6 +29,11 @@ def teardown_request(exception):
|
||||||
if db is not None:
|
if db is not None:
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
class ContactForm(Form):
|
||||||
|
name = TextField('Name', [validators.Length(min=4, max=25)])
|
||||||
|
email = TextField('Email Address', [validators.Length(min=6, max=35)])
|
||||||
|
message = TextAreaField('Message', [validators.Length(min=6, max=5000)])
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def home():
|
def home():
|
||||||
g.db.execute('SELECT * FROM blog_posts ORDER BY updated_on DESC')
|
g.db.execute('SELECT * FROM blog_posts ORDER BY updated_on DESC')
|
||||||
|
@ -57,12 +63,16 @@ def projects():
|
||||||
|
|
||||||
@app.route('/contact', methods=['GET', 'POST'])
|
@app.route('/contact', methods=['GET', 'POST'])
|
||||||
def contact():
|
def contact():
|
||||||
if request.method == 'POST':
|
form = ContactForm(request.form)
|
||||||
request.form['name']
|
if request.method == 'POST' and form.validate():
|
||||||
request.form['email']
|
msg = Message(subject='New Message From wbrawner.com',
|
||||||
request.form['message']
|
body="Name: {0}\nEmail: {1}\nMessage: {2}".format(request.form['name'], request.form['email'], request.form['message']),
|
||||||
|
recipients=["billybrawner@gmail.com"])
|
||||||
|
mail.send(msg)
|
||||||
|
flash('Thanks, your message was sent.')
|
||||||
|
return redirect(url_for('contact'))
|
||||||
else:
|
else:
|
||||||
return render_template('contact.html')
|
return render_template('contact.html', form=form)
|
||||||
|
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
|
|
11
requirements.txt
Normal file
11
requirements.txt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
blinker==1.4
|
||||||
|
Flask==0.10.1
|
||||||
|
Flask-DebugToolbar==0.10.0
|
||||||
|
Flask-Mail==0.9.1
|
||||||
|
Flask-MySQLdb==0.2.0
|
||||||
|
itsdangerous==0.24
|
||||||
|
Jinja2==2.8
|
||||||
|
MarkupSafe==0.23
|
||||||
|
mysqlclient==1.3.7
|
||||||
|
Werkzeug==0.11.4
|
||||||
|
WTForms==2.1
|
|
@ -4,7 +4,7 @@ CREATE TABLE blog_posts (
|
||||||
text VARCHAR( 10000 ) DEFAULT NULL ,
|
text VARCHAR( 10000 ) DEFAULT NULL ,
|
||||||
category VARCHAR( 50 ) DEFAULT NULL ,
|
category VARCHAR( 50 ) DEFAULT NULL ,
|
||||||
tags VARCHAR( 100 ) DEFAULT NULL ,
|
tags VARCHAR( 100 ) DEFAULT NULL ,
|
||||||
url VARCHAR(500) DEFAULT NULL UNIQUE,
|
url VARCHAR(100) DEFAULT NULL UNIQUE,
|
||||||
created_on DATETIME NOT NULL ,
|
created_on DATETIME NOT NULL ,
|
||||||
updated_on TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP
|
updated_on TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP
|
||||||
);
|
);
|
12
templates/_formhelper.html
Normal file
12
templates/_formhelper.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{% macro render_field(field) %}
|
||||||
|
<dt>{{ field.label }}
|
||||||
|
<dd>{{ field(**kwargs)|safe }}
|
||||||
|
{% if field.errors %}
|
||||||
|
<ul class=errors>
|
||||||
|
{% for error in field.errors %}
|
||||||
|
<li>{{ error }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
</dd>
|
||||||
|
{% endmacro %}
|
|
@ -2,11 +2,14 @@
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="section" id="contact">
|
<div class="section" id="contact">
|
||||||
<h2>contact</h2>
|
<h2>contact</h2>
|
||||||
<form method="{{ url_for('contact') }}">
|
{% from "_formhelper.html" import render_field %}
|
||||||
<input type="text" name="name">
|
<form method="post" action="{{ url_for('contact') }}">
|
||||||
<input type="text" name="email">
|
<dl>
|
||||||
<textarea name="message"></textarea>
|
{{ render_field(form.name) }}
|
||||||
<input type="submit" value="submit">
|
{{ render_field(form.email) }}
|
||||||
|
{{ render_field(form.message) }}
|
||||||
|
</dl>
|
||||||
|
<p style="margin-left: 40px;"><input type="submit" value="Send">
|
||||||
</form>
|
</form>
|
||||||
<div class="one-half">
|
<div class="one-half">
|
||||||
<a class="twitter-timeline" href="https://twitter.com/BillyBrawner1" data-widget-id="706308392311136256">Tweets by @BillyBrawner1</a>
|
<a class="twitter-timeline" href="https://twitter.com/BillyBrawner1" data-widget-id="706308392311136256">Tweets by @BillyBrawner1</a>
|
||||||
|
|
Loading…
Reference in a new issue