Skip to content
Snippets Groups Projects
Commit c61d8d7a authored by Brice Johnson's avatar Brice Johnson
Browse files

Set up MVC filesystem for flask and jinja

parent 35708ee9
No related branches found
No related tags found
No related merge requests found
Showing
with 132 additions and 0 deletions
web: python runserver.py
# -*- coding: utf-8 -*-
__version__ = '0.1'
from flask import Flask
from flask_debugtoolbar import DebugToolbarExtension
app = Flask('project')
app.config['SECRET_KEY'] = 'random'
app.debug = True
toolbar = DebugToolbarExtension(app)
from project.controllers import *
import os
import glob
__all__ = [os.path.basename(
f)[:-3] for f in glob.glob(os.path.dirname(__file__) + "/*.py")]
# -*- coding: utf-8 -*-
from project import app
from flask import render_template, request
from flask.ext.wtf import Form, TextField, validators
class CreateForm(Form):
text = TextField(u'Text:', [validators.Length(min=1, max=20)])
@app.route('/')
def start():
return render_template('printer/index.html')
@app.route('/print', methods=['GET', 'POST'])
def printer():
form = CreateForm(request.form)
if request.method == 'POST' and form.validate():
from project.models.Printer import Printer
printer = Printer()
printer.show_string(form.text.data)
return render_template('printer/index.html')
return render_template('printer/print.html', form=form)
# -*- coding: utf-8 -*-
from flask import flash
class Printer(object):
def show_string(self, text):
if text == '':
flash("You didn't enter any text to flash")
else:
flash(text + "!!!")
Flask==0.10
Flask-WTF==0.8.3
Jinja2==2.7
Flask-DebugToolbar==0.8.0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from project import app
if __name__ == '__main__':
port = int(os.environ.get("PORT", 8080))
app.run('0.0.0.0', port=port)
File moved
File moved
File moved
File moved
File moved
File moved
body {
font-family: sans-serif;
background: #eee;
}
a,h1,h2 {
color: #377BA8;
}
h1,h2 {
font-family: 'Georgia', serif;
margin: 0;
}
h1 {
border-bottom: 2px solid #eee;
}
h2 {
font-size: 1.2em;
}
.page {
margin: 2em auto;
width: 35em;
border: 5px solid #ccc;
padding: 0.8em;
background: white;
}
.entries {
list-style: none;
margin: 0;
padding: 0;
}
.entries li {
margin: 0.8em 1.2em;
}
.entries li h2 {
margin-left: -1em;
}
.add-entry {
font-size: 0.9em;
border-bottom: 1px solid #ccc;
}
.add-entry dl {
font-weight: bold;
}
.metanav {
text-align: right;
font-size: 0.8em;
padding: 0.3em;
margin-bottom: 1em;
background: #fafafa;
}
.flash {
background: #CEE5F5;
padding: 0.5em;
border: 1px solid #AACBE2;
}
.error {
background: #F0D6D6;
padding: 0.5em;
}
\ No newline at end of file
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment