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

Refactor boilerplate template

parent ea00488f
Branches
No related tags found
No related merge requests found
# Personal virtualenv
.hodor
# -*- 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")]
File added
# -*- 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)
File added
# -*- 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 + "!!!")
File added
File added
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 %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment