-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
69 lines (49 loc) · 1.71 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask , make_response, render_template, jsonify, send_from_directory,request,redirect
from flask.ext.login import login_required , current_user
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy.sql.expression import func, select
import os
from werkzeug import secure_filename
import json
import random
from config import *
app = Flask(__name__, instance_relative_config=True,static_url_path="/static")
db = SQLAlchemy(app)
app.config['SECRET_KEY'] = '$&^&B&*^*MN&*CDMN&*()B^&*()P^&_N*NM(P)*&D()&*^'
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.debug = True
class Quote(db.Model):
id = db.Column(db.Integer, primary_key = True, autoincrement=True)
content = db.Column(db.Text)
author = db.Column(db.String(254))
category = db.Column(db.String(254))
def __init__(self):
pass
@app.route('/')
def index():
quotes = Quote.query.all()[:20]
return render_template('index.html',quotes=quotes)
@app.route('/random')
def reply():
print request.remote_addr
while True:
quote = Quote.query.order_by(func.rand()).first()
if len(quote.content) < 150:
break
q = {}
q['content'] = quote.content
q['author'] = quote.author
return json.dumps(q)
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file:
filename = secure_filename(file.filename)
filename = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(filename)
return render_template('upload.html',alert='File Uploaded Succesfully!')
return render_template('upload.html')
if __name__ == '__main__':
app.run('0.0.0.0')