#! /usr/bin/python # ! -*- coding: utf-8 -*- __author__ = 'asatake' from flask import Flask, render_template, request, redirect, url_for from flask.ext.navigation import Navigation import datetime import os app = Flask(__name__) nav = Navigation() nav.init_app(app) nav.Bar('top', [ nav.Item('Home', 'index'), nav.Item('About', 'about'), nav.Item('Link', 'link'), ]) # return my age def old(): d1 = datetime.date.today() d2 = datetime.date(1994, 2, 11) comp = (d1 - d2) s = str(comp).split()[0] return int(s) // 365 @app.route('/') @app.route('/<name>')
@login_manager.user_loader def load_user(userid): return User(userid) #returns a database connection for MySQL def connect_to_database_mysql(): return MySQLdb.connect(host=config['HOST'], port=config['PORT'],\ user=config['USER'], passwd=config['PASSWD'], db=config['SQLDB'], charset=config['CHARSET']) #setup navbar nav = Navigation(app) nav.Bar('top', [nav.Item('Basket','basket_page.show_basket'), nav.Item('Home', 'main'), nav.Item('Catalogue', 'catalogue_page.show_catalogue_index'), nav.Item('Account','account_page.show_account'), nav.Item('Log In','login_page.show_login'), nav.Item('Log Out','login_page.show_logout'), nav.Item('Register', 'signup_page.show_signup')]) DBFUNC = connect_to_database_mysql ##Setup DB connection @app.before_request def before_request(): try: #setup DB g.db = DBFUNC() except Exception as e: print e
app.config.update(mail_settings) mail = Mail(app) mysql.init_app(app) api = Api(app) app.config["MONGO_URI"] = "mongodb://localhost:27017/Comm" mongo = PyMongo(app) api.add_resource(GetAllItems, '/rest/F') api.add_resource(GetOneItems, '/rest/F/<_userId>') nav = Navigation() nav.init_app(app) nav.Bar('top', [ nav.Item('Home', 'index'), nav.Item('Table', 'view'), nav.Item('Match', 'Z'), nav.Item('Match Results', 'MatchesResult'), nav.Item('Fixtures', 'Fixtures'), nav.Item('Sign Up', 'showSignUp', items=[nav.Item('Log In', 'login')]), ]) login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = "login" class User(UserMixin): def __init__(self, id): self.id = id def __repr__(self): return "%d/%s/%s" % (self.id)
from init_app import app from flask import render_template, flash, redirect, url_for from models import GalleryItem, Product, Creator, MailingList from flask.ext.navigation import Navigation from profile import creatorpage from forms import MailingListForm from init_app import db, mail from flask_mail import Message from token import generate_confirmation_token, confirm_token import datetime nav = Navigation(app) nav.Bar('top', [ nav.Item('Art', 'gallery'), nav.Item('Products', 'products'), nav.Item('Creators', 'creators'), nav.Item('About', 'about') ]) app.register_blueprint(creatorpage) # Custom error handlers @app.errorhandler(500) def internal_error(error): db.session.rollback() return "a server error occurred", 500 # Custom filters for jinja templates @app.template_filter('tagset')
import collections import json import simplejson import flask from flask.ext.navigation import Navigation from . import db app = flask.Flask(__name__) nav = Navigation(app) nav.Bar('top', [ nav.Item('Home', 'index'), nav.Item('Upload', 'upload_file'), nav.Item('Reports', 'list_reports'), ]) @app.route('/') def index(): return flask.render_template('index.html') @app.route('/upload', methods=['GET', 'POST']) def upload_file(): if flask.request.method == 'POST': f = flask.request.files['validation_report'] uploaded_by = flask.request.form.get('uploaded_by') writeup = flask.request.form.get('writeup') x = f.read()
from flask import Flask, Blueprint, render_template from flask.ext.navigation import Navigation app = Flask(__name__) nav = Navigation(app) pocket = Blueprint(__name__, 'pocket', url_prefix='/pocket') app.register_blueprint(pocket) navbar = nav.Bar('top', [ nav.Item(u'Home', endpoint='home'), nav.Item(u'Pocket', endpoint='pocket') ]) pocket_navbar = nav.Bar('pocket', [ nav.Item(u'Back', endpoint='pocket'), nav.Item(u'Article', endpoint='pocket.article'), nav.Item(u'Video', endpoint='pocket.video'), ], alias={'back': nav.ItemReference('pocket')}) @app.route('/') def home(): return render_template('nested/home.html') @app.route('/pocket') def pocket(): return render_template('nested/pocket.html')
from flask import Flask, render_template from flask.ext.navigation import Navigation app = Flask() nav = Navigation(app) navbar = nav.Bar('top', [ nav.Item(u'Home', endpoint='home'), nav.Item(u'Latest Article', endpoint='article', args=lambda: {'aid': 1}), nav.Item(u'More', endpoint='more', url='//example.com/more'), ]) @navbar.initializer def init_navbar(nav): # yield items from database here def yield_items(): for i in range(2): external_url = '//example.com/x/%d' % i yield nav.Item('X:%d' % i, endpoint='x-serial', url=external_url) # extend your bar nav['top'].extend(yield_items(), after_endpoint='article') @app.route('/') def home(): return render_template('simple/home.html') @app.route('/article/<int:aid>')
#limit content size def limit_content_length(max_length): def decorator(f): @wraps(f) def wrapper(*args, **kwargs): cl = request.content_length if cl is not None and cl > max_length: abort(413) return f(*args, **kwargs) return wrapper return decorator #MAIN ROUTES navbar_top = nav.Bar('top', [ nav.Item('Index', 'index'), nav.Item('Upsert', 'upsert'), nav.Item('Find', 'find'), nav.Item('Report', 'report'), ]) @app.route("/") def index(): return render_template('index.html') @app.route("/upsert", methods=['GET']) @basic_auth.required @limiter.limit("100/hour") def upsert(): userinputs = [x for x in handle.trackingdb.find().sort("_id",-1).limit(25)] return render_template('upsert.html', userinputs=userinputs) @app.route("/find", methods=['GET'])
register_blueprints(app) # navigation part nav = Navigation() nav.init_app(app) products_array = [] categs = Categories.objects.all().order_by('title') for el in categs: products_array.append(nav.Item(el.title, 'products', {'product': el.title})) nav.Bar('top', [ nav.Item( 'Продукция', 'products', {'product': 'Бензин'}, items=products_array), nav.Item('Доставка', 'delivery'), nav.Item('Дилеры', 'dilers'), nav.Item('Контакты', 'contacts') ]) @app.route('/contacts') def contacts(): return render_template('oilsite/contacts.html') @app.route('/dilers') def dilers(): return render_template('oilsite/dilers.html')
from app import app from flask import request, flash from flask import render_template from flask import url_for, redirect from flask_sqlalchemy import SQLAlchemy from app.forms import AliveCalculatorForm from app.models import Input, db from flask.ext.navigation import Navigation nav = Navigation(app) nav.Bar('top', [ nav.Item('Home', 'index'), nav.Item('New Calculation', 'new'), nav.Item('History', 'history') ]) @app.route("/") @app.route("/index") def index(): return render_template("index.html") @app.route("/show/<int:id>/") def show(id): iput = Input.query.get_or_404(id) return render_template("show.html", iput=iput) @app.route("/new", methods=('GET', 'POST')) def new():
# inputs training_data = 'data/titanic_train.csv' include = ['Age', 'Sex', 'Embarked', 'Survived'] dependent_variable = include[-1] model_directory = 'model' model_file_name = '%s/model.pkl' % model_directory model_columns_file_name = '%s/model_columns.pkl' % model_directory # These will be populated at training time model_columns = None clf = None nav.Bar('top', [ nav.Item('Home', 'index'), nav.Item('Train', 'train'), nav.Item('Wipe', 'wipe') ]) @app.route('/') def index(): return render_template('index.html') @app.route('/predict_terminal', methods=['POST', 'GET']) def predict_terminal(): if os.listdir(model_directory) != []: json_ = json.dumps(request.json) json_ = json.loads(json_)