TDDD83 Kandidatprojekt datateknik
Information
Setting up a python-flask application on IDA openshift
- Pre-requisite: Install rhc tool
If you get dependency problems installing rhc try this:- gem install rubygems-update
- update_rubygems
- gem install rhc
- First setup your account on openshift.ida.liu.se:
rhc setup -l liu-id --server openshift.ida.liu.se
Follow the instructions on openshift for setting up your machine:
Linux
Mac
Windows
- Create a python application:
rhc create-app flask python-2.7
- Check out your application (sometimes create-app checks out the
application in which case next step is not necessary):
rhc git-clone flask
(accept the RSA fingerprint) - Edit setup.py (this so openshift knows to install Flask for your application)
For know it should look like this:from setuptools import setup setup(name='YourAppName', version='1.0', description='OpenShift App', author='Your Name', author_email='example@example.com', url='http://www.python.org/sigs/distutils-sig/', install_requires=['Flask'], )
- Add , commit and push your edited file:
git add setup.py
git commit -m "Added flask for install" setup.py
Push your changed file to openshift
git push
- Create the flask server-file server.py it should look
something like this:
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run()
- Add, commit and push your server.py:
git add server.py
git -m "initial server" server.py
git push
- Edit wsgi.py
#!/usr/bin/python import os virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/' virtualenv = os.path.join(virtenv, 'bin/activate_this.py') try: execfile(virtualenv, dict(__file__=virtualenv)) except IOError: pass # # IMPORTANT: Put any additional includes below this line. If placed above this # line, it's possible required libraries won't be in your searchable path # from server import app as application
(Remove everything else in the file) - Add, commit and push your edited
git add wsgi.py
git commit -m "import app from server.py"
git push
- Go to your web application to see that everything is working:
To find the URL to your application use:
rhc show-app flask
Sidansvarig: Martin Sjölund
Senast uppdaterad: 2015-04-02