This is my template file for new flask projects
Setup Instructions:
-
Clone template project:
- git clone [email protected]:icecreammatt/flask-empty.git project-name.git
- cd project-name.git
- git branch project-name
- git checkout project-name
-
Setup virtualenv: (From inside the project-name folder)
If virtualenv isn't installed run, easy_install pip; pip install virtualenv
virtualenv venv
. venv/bin/activate
pip install Flask
- Run Sample:
python run.py
REQUIREMENTS: pip install Flask pip install pyMongo pip install bcrypt pip install flask_cors pip install mongoengine reference: http://docs.mongoengine.org/guide pip install mongoengine_goodjson reference: https://pypi.python.org/pypi/mongoengine_goodjson/0.10.1 pip install flask-socketio reference: https://github.com/miguelgrinberg/Flask-SocketIO
EXAMPLE ON SWITCHING DATABASE:
'''
mongo = Connection(None, None, 'jeff-database')
mongo.collection.hijeff.insert({'yay': 'yay'})
'''
try:
Connection(None, None, 'flask-database')
user = User.find_user(page=1, per_page=15)
resp = jsonify({'User': user, 'message': 'Successfully inserted!'})
except Exception as e:
resp = jsonify({'arg': e.args[0], 'message': 'Unexpected error occured!'})
resp.status_code = 500
return make_response(resp)
NATIVE QUERY:
if user_collection is None:
resp = jsonify({'message': 'User not ' + email + ' found'})
resp.status_code = 500
else:
json_docs = [json.dumps(doc, default=json_util.default) for doc in [user_collection]]
resp = jsonify(data=json_docs)
resp.status_code = 200
return resp