integrated flask template
This commit is contained in:
20
app/__init__.py
Normal file
20
app/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
Python Aplication Template
|
||||
Licence: GPLv3
|
||||
"""
|
||||
|
||||
from flask import Flask
|
||||
from flask.ext.sqlalchemy import SQLAlchemy
|
||||
|
||||
|
||||
app = Flask(__name__,static_url_path='',static_folder='build')
|
||||
|
||||
#Configuration of application, see configuration.py, choose one and uncomment.
|
||||
#app.config.from_object('configuration.ProductionConfig')
|
||||
app.config.from_object('app.configuration.DevelopmentConfig')
|
||||
#app.config.from_object('configuration.TestingConfig')
|
||||
|
||||
db = SQLAlchemy(app) #flask-sqlalchemy
|
||||
|
||||
from app import views, models
|
||||
29
app/configuration.py
Normal file
29
app/configuration.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
Python Aplication Template
|
||||
Licence: GPLv3
|
||||
"""
|
||||
|
||||
class Config(object):
|
||||
"""
|
||||
Configuration base, for all environments.
|
||||
"""
|
||||
DEBUG = False
|
||||
TESTING = False
|
||||
DATABASE_URI = 'sqlite:///application.db'
|
||||
BOOTSTRAP_FONTAWESOME = True
|
||||
SECRET_KEY = "MINHACHAVESECRETA"
|
||||
CSRF_ENABLED = True
|
||||
|
||||
#Get your reCaptche key on: https://www.google.com/recaptcha/admin/create
|
||||
#RECAPTCHA_PUBLIC_KEY = "6LffFNwSAAAAAFcWVy__EnOCsNZcG2fVHFjTBvRP"
|
||||
#RECAPTCHA_PRIVATE_KEY = "6LffFNwSAAAAAO7UURCGI7qQ811SOSZlgU69rvv7"
|
||||
|
||||
class ProductionConfig(Config):
|
||||
DATABASE_URI = 'mysql://user@localhost/foo'
|
||||
|
||||
class DevelopmentConfig(Config):
|
||||
DEBUG = True
|
||||
|
||||
class TestingConfig(Config):
|
||||
TESTING = True
|
||||
18
app/forms.py
Normal file
18
app/forms.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
Python Aplication Template
|
||||
Licence: GPLv3
|
||||
"""
|
||||
|
||||
from flask.ext.wtf import Form, TextField, TextAreaField, DateTimeField, PasswordField
|
||||
from flask.ext.wtf import Required
|
||||
|
||||
class ExampleForm(Form):
|
||||
title = TextField(u'Título', validators = [Required()])
|
||||
content = TextAreaField(u'Conteúdo')
|
||||
date = DateTimeField(u'Data', format='%d/%m/%Y %H:%M')
|
||||
#recaptcha = RecaptchaField(u'Recaptcha')
|
||||
|
||||
class LoginForm(Form):
|
||||
user = TextField(u'Usuário', validators = [Required()])
|
||||
password = PasswordField(u'Senha', validators = [Required()])
|
||||
39
app/models.py
Normal file
39
app/models.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
Python Aplication Template
|
||||
Licence: GPLv3
|
||||
"""
|
||||
|
||||
from app import db
|
||||
|
||||
class Post(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
title = db.Column(db.String(80))
|
||||
body = db.Column(db.Text)
|
||||
pub_date = db.Column(db.DateTime)
|
||||
|
||||
category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
|
||||
category = db.relationship('Category',
|
||||
backref=db.backref('posts', lazy='dynamic'))
|
||||
|
||||
def __init__(self, title, body, category, pub_date=None):
|
||||
self.title = title
|
||||
self.body = body
|
||||
if pub_date is None:
|
||||
pub_date = datetime.utcnow()
|
||||
self.pub_date = pub_date
|
||||
self.category = category
|
||||
|
||||
def __repr__(self):
|
||||
return '<Post %r>' % self.title
|
||||
|
||||
|
||||
class Category(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(50))
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def __repr__(self):
|
||||
return '<Category %r>' % self.name
|
||||
27
app/views.py
Normal file
27
app/views.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
Python Aplication Template
|
||||
Licence: GPLv3
|
||||
"""
|
||||
|
||||
from flask import url_for, redirect, render_template, flash, g, session
|
||||
from app import app
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return app.send_static_file('index.html')
|
||||
|
||||
@app.route('/api/addpost',methods=['POST'])
|
||||
def walle_morph():
|
||||
word = request.args.get('word','water')
|
||||
pos_req = request.args.get('pos','N')
|
||||
pos = pos_req if pos_req != '' else 'N';
|
||||
return json.dumps(get_morph(word,pos))
|
||||
|
||||
@app.route('/api/xmlfiles')
|
||||
def walle_xmlfiles():
|
||||
xml_files = map(os.path.basename,glob.glob(xmlDir+'*.xml'))
|
||||
return json.dumps(xml_files)
|
||||
|
||||
|
||||
# ====================
|
||||
Reference in New Issue
Block a user