Project currently hosted at https://i6.cims.nyu.edu/~ab1258/flask-mongodb-example/flask.cgi
The credentials for logging into a MongoDB database must be stored in a file named .env, which is not included in this repository for security reasons.
- make a copy of the file named
env.exampleand save it as.env - edit the
.envfile and enter your own database credentials into each of the variables where indicated
To run this app locally, first clone this repository to your local machine...
git clone url-to-this-repository
... and then do the following:
This command creates a new virtual environment with the name .venv:
python3 -m venv .venvTo activate the virtual environment named .venv...
On Mac:
source .venv/bin/activateOn Windows:
.venv\Scripts\activate.batThe file named, requirements.txt contains a list of dependencies - other Python modules that this app depends upon to run.
To install the dependencies into the currently-active virtual environment, use pip, the default Python "package manager" - software that takes care of installing the correct version of any module into your in the correct place for the current environment.
pip3 install -r requirements.txt- define two environment variables from the command line:
export FLASK_APP=appandexport FLASK_ENV=development - copy the file named
env.exampleinto a new file named.env, and enter your own MongoDB database connection credentials into that file where indicated. - start flask with
flask run- this will output an address at which the app is running locally, e.g. https://127.0.0.1:5000. Visit that address in a web browser.
The following steps outline how to host this application on NYU's i6.cims.nyu.edu web server. Other servers may vary.
- Familiarize yourself with web hosting steps on a CIMS server from the link: https://cims.nyu.edu/webapps/content/systems/userservices/webhosting.
- remotely log into the server using
ssh. - navigate into your web server account's
public_htmldirectory usingcd public_html. - clone this repository with
git clone url-to-this-repository - once cloned, copy the file named
env.exampleinto a new file named.env(usingcp env.example .env), and enter your own MongoDB database connection credentials into that file where indicated. Save it. - Make the files named
flask.cgiandapp.pyexecutable by all with the command,chmod u+x flask.cgiandchmod u+x app.py. - Your app should now be live at https://i6.cims.nyu.edu/~$USER/$flask-app-directory/flask.cgi, where
$USERis replaced with your own i6 username and$flask-app-directoryis replaced with the name of the sub-directory withinpublic_htmlwhere your flask app code resides.