Skip to content
Snippets Groups Projects
Verified Commit 46b382b9 authored by Sachin Kamath's avatar Sachin Kamath
Browse files

Initial boilerplate template

parents
No related branches found
No related tags found
No related merge requests found
web: python runserver.py
A simple boilerplate application following the MVC pattern using Flask micro python framework.
It basically here to be my base skeleton for new python web applications
Demo : http://flask-mvc-salimane.herokuapp.com/
Dependencies :
git clone git://github.com/salimane/flask-mvc.git
cd flask-mvc
if you have old version of project: pip uninstall -r requirements.txt
pip install -r requirements.txt
To run:
python runserver.py
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/salimane/flask-mvc/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
# -*- 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 *
File added
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_wtf import FlaskForm
from wtforms import StringField
from wtforms.validators import DataRequired
class CreateForm(FlaskForm):
text = StringField('name', validators=[DataRequired()])
@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 + "!!!")
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
<!doctype html>
<head>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}">
<title>Flask-MVC</title>
</head>
<body>
<a style="text-align:center" href="{{ url_for('start') }}">Home</a>
<a style="text-align:center" href="http://salimane.com">About</a>
<div class="page">
<h1>Flask MVC Boilerplate</h1>
{% for message in get_flashed_messages() %}
<div class="flash">{{ message }}</div>
{% endfor %}
{% macro render_error(field) %}
{% if field.errors %}
{% for error in field.errors %}<span class='error'>{{ error }}</span>{% endfor %}
{% endif %}
{% endmacro %}
{% block body %}{% endblock %}
</div>
</body>
</html>
{% extends "layout/layout.html" %}
{% block body %}
<ul>
<p>
<a href="{{ url_for('printer') }}">Click here to print!</a>
</p>
</ul>
{% endblock %}
{% extends "layout/layout.html" %}
{% block body %}
<form action="{{ url_for('printer') }}" method="post">
{{ form.csrf_token }}
<dl>
<dd>{{ form.text.label }} {{ form.text(size=20) }} {{ render_error(form.text) }}</dd>
<dd><input type="submit" value="Flash"/></dd>
</dl>
</form>
{% endblock %}
#!/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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment