コード例 #1
0
def connect_to_db(init_type):
    # connect to database
    if init_type == "openshift" :
        app.config['MYSQL_USER']     =  os.environ['OPENSHIFT_MYSQL_DB_USERNAME']
        app.config['MYSQL_PASSWORD'] =  os.environ['OPENSHIFT_MYSQL_DB_PASSWORD']
        app.config['MYSQL_DB']       = 'dkdbprojects'
        app.config['MYSQL_HOST']     =  os.environ['OPENSHIFT_MYSQL_DB_HOST']
    else :
        app.config['MYSQL_USER']     = '******'
        app.config['MYSQL_PASSWORD'] = '******'
        app.config['MYSQL_DB']       = 'dkdbprojects'
        app.config['MYSQL_HOST']     = 'localhost'
    global mysql
    mysql = MySQL()
    mysql.init_app(app)
    return
コード例 #2
0
from werkzeug import generate_password_hash, check_password_hash
from werkzeug.wsgi import LimitedStream
import uuid
import os

mysql = MySQL()
# print mysql
app = Flask(__name__)
app.secret_key = 'why would I tell you my secret key?'

# MySQL configurations
app.config['MYSQL_DATABASE_USER'] = '******'
app.config['MYSQL_DATABASE_PASSWORD'] ='******'
app.config['MYSQL_DATABASE_DB'] = 'emailSpam'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)

# Default setting
pageLimit = 5

class StreamConsumingMiddleware(object):

    def __init__(self, app):
        self.app = app

    def __call__(self, environ, start_response):
        stream = LimitedStream(environ['wsgi.input'],
                               int(environ['CONTENT_LENGTH'] or 0))
        environ['wsgi.input'] = stream
        app_iter = self.app(environ, start_response)
        try:
コード例 #3
0
ファイル: application.py プロジェクト: JamesBream/PixelGram
import resizr

application = Flask(__name__)
mysql = MySQL()

# 504 bit session key
application.secret_key  = '?KzNp>j0-7ec;4c9zG]@tjrBy3uCZNeEsDFm*!%buG7A97?#3ANL*97;D?(jpe9'

# Config MySQL
# Don't run as root in production!

application.config['MYSQL_USER'] = '******'
application.config['MYSQL_PASSWORD'] = '******'
application.config['MYSQL_DB'] = 'PixelGram'
application.config['MYSQL_HOST'] = 'localhost'
mysql.init_app(application)

# Define uploads folder and allowed file types - Should not be changed for now!
application.config['UPLOAD_FOLDER'] = 'static/uploads'
application.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024
ALLOWED_EXTENSIONS = set(['jpg'])

# Check the uploads folder exists, otherwise create it
print("INFO: Checking if upload folder exists")
if not os.path.exists(application.config['UPLOAD_FOLDER']):
    try:
        print("WARN: Upload folder does not exist, creating it")
        os.makedirs(application.config['UPLOAD_FOLDER'])
    except Exception as e:
        print(e)
        
コード例 #4
0
ファイル: views.py プロジェクト: JamesBream/Flixr
# System imports
import re, json
# Third party imports
import bleach, requests
from flask import render_template, redirect, request, session
from flask.ext.mysqldb import MySQL
from werkzeug import generate_password_hash, check_password_hash
from app import application

mysql = MySQL()
mysql.init_app(application)

@application.route('/')
@application.route('/index')
def index():
    if session.get('user'):
        return redirect('/discover')
    return render_template('index.html')


@application.route('/register', methods=['GET', 'POST'])
def register():
    title = "Flixr - Register"
    if request.method == "GET":
        return render_template('register.html',
                                title=title)
    
    elif request.method == "POST":
        try:
            # Request POST values and sanitise input of HTML where necessary
            _firstname = bleach.clean(request.form['inputFirstName'])