-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflaskpaste.py
More file actions
38 lines (28 loc) · 982 Bytes
/
flaskpaste.py
File metadata and controls
38 lines (28 loc) · 982 Bytes
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
from flask import Flask, render_template, request, redirect
from flask.ext.pymongo import PyMongo
app = Flask(__name__)
app.config.from_pyfile('app.cfg')
mongo = PyMongo(app)
@app.route('/store_paste', methods=['POST'])
def store_paste():
id = get_next_paste_id()
store = {'_id': id,
'code': '\n'+request.form['code'],
'language': request.form['language']}
mongo.db.pastes.insert(store)
return redirect('/get_paste/%d' % id)
def get_next_paste_id():
cursor = mongo.db.pastes.find({}, {'_id'}).sort('_id', -1).limit(1)
try:
return cursor[0]['_id']+1
except IndexError:
return 0
@app.route('/get_paste/<int:pasteid>')
def get_paste(pasteid=0):
paste = mongo.db.pastes.find_one_or_404({'_id': pasteid})
return render_template('show_code.html', paste=paste)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7800)