-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0 parents
commit a9b9e47
Showing
21 changed files
with
1,363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# mac junk | ||
.DS_Store | ||
|
||
# visual studio code junk | ||
.vscode/ | ||
.vscode/settings.json | ||
|
||
# emacs backups | ||
*~ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Flask-MongoDB Web App Example | ||
|
||
An example of a full-stack web application, built in Python with `flask` and `pymongo`. | ||
|
||
## Setup | ||
|
||
### Build and launch the database | ||
|
||
- install and run [docker desktop](https://www.docker.com/get-started) | ||
- create a [dockerhub](https://hub.docker.com/signup) account | ||
- run command, `docker run --name mongodb_dockerhub -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=secret -d mongo:latest` | ||
|
||
The back-end code will integrate with this database. However, it may be occasionally useful interact with the database directly from the command line: | ||
|
||
- connect to the database server from the command line: `docker exec -ti mongodb_dockerhub mongosh -u admin -p secret` | ||
- show the available databases: `show dbs` | ||
- select the database used by this app: `use web-app-example-db` | ||
- show the documents stored in the `messages` collection: `db.messages.find()` - this will be empty at first, but will later be populated by the app. | ||
- exit the database shell whenever you have had your fill: `exit` | ||
|
||
If you have trouble running Docker on your computer, use a database hosted on [MongoDB Atlas](https://www.mongodb.com/atlas) instead. Atlas is a "cloud" MongoDB database service with a free option. Create a database there, and make note of the connection string, username, password, etc. | ||
|
||
### Create a `.env` file | ||
|
||
A file named `.env` is necessary to run the application. This file contains sensitive environment variables holding credentials such as the database connection string, username, password, etc. This file should be excluded from version control in the `[.gitignore](.gitignore)` file. | ||
|
||
An example file named `env.example` is given. Copy this into a file named `.env` and edit the values to match your database. If following the instructions and using Docker to run the database, the values should be: | ||
|
||
``` | ||
MONGO_HOST=localhost:27017 | ||
MONGO_USER=admin | ||
MONGO_PASSWORD=secret | ||
MONGO_DBNAME=web-app-example-db | ||
``` | ||
|
||
The other values can be left alone. | ||
|
||
### Set up a Python virtual environment | ||
|
||
This command creates a new virtual environment with the name `.venv`: | ||
|
||
```bash | ||
python3 -m venv .venv | ||
``` | ||
|
||
### Activate the virtual environment | ||
|
||
To activate the virtual environment named `.venv`... | ||
|
||
On Mac: | ||
|
||
```bash | ||
source .venv/bin/activate | ||
``` | ||
|
||
On Windows: | ||
|
||
```bash | ||
.venv\Scripts\activate.bat | ||
``` | ||
|
||
### Install dependencies into the virtual environment | ||
|
||
The 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. | ||
|
||
```bash | ||
pip3 install -r requirements.txt | ||
``` | ||
|
||
### Run the app | ||
|
||
1. 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. | ||
1. in some cases, the command `flask` will not be found when attempting `flask run`... you can alternatively launch it with `python3 -m flask run --host=0.0.0.0 --port=10000`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from flask import Flask, render_template, request, redirect, url_for, make_response | ||
from markupsafe import escape | ||
import pymongo | ||
import datetime | ||
from bson.objectid import ObjectId | ||
import os | ||
import subprocess | ||
|
||
# instantiate the app | ||
app = Flask(__name__) | ||
|
||
# load credentials and configuration options from .env file | ||
# if you do not yet have a file named .env, make one based on the template in env.example | ||
import credentials | ||
config = credentials.get() | ||
|
||
# turn on debugging if in development mode | ||
if config['FLASK_ENV'] == 'development': | ||
# turn on debugging, if in development | ||
app.debug = True # debug mnode | ||
|
||
# make one persistent connection to the database | ||
connection = pymongo.MongoClient(config['MONGO_HOST'], 27017, | ||
username=config['MONGO_USER'], | ||
password=config['MONGO_PASSWORD'], | ||
authSource=config['MONGO_DBNAME']) | ||
db = connection[config['MONGO_DBNAME']] # store a reference to the database | ||
|
||
# set up the routes | ||
|
||
@app.route('/') | ||
def home(): | ||
""" | ||
Route for the home page | ||
""" | ||
return render_template('index.html') | ||
|
||
|
||
@app.route('/read') | ||
def read(): | ||
""" | ||
Route for GET requests to the read page. | ||
Displays some information for the user with links to other pages. | ||
""" | ||
docs = db.exampleapp.find({}).sort("created_at", -1) # sort in descending order of created_at timestamp | ||
return render_template('read.html', docs=docs) # render the read template | ||
|
||
|
||
@app.route('/create') | ||
def create(): | ||
""" | ||
Route for GET requests to the create page. | ||
Displays a form users can fill out to create a new document. | ||
""" | ||
return render_template('create.html') # render the create template | ||
|
||
|
||
@app.route('/create', methods=['POST']) | ||
def create_post(): | ||
""" | ||
Route for POST requests to the create page. | ||
Accepts the form submission data for a new document and saves the document to the database. | ||
""" | ||
name = request.form['fname'] | ||
message = request.form['fmessage'] | ||
|
||
|
||
# create a new document with the data the user entered | ||
doc = { | ||
"name": name, | ||
"message": message, | ||
"created_at": datetime.datetime.utcnow() | ||
} | ||
db.exampleapp.insert_one(doc) # insert a new document | ||
|
||
return redirect(url_for('read')) # tell the browser to make a request for the /read route | ||
|
||
|
||
@app.route('/edit/<mongoid>') | ||
def edit(mongoid): | ||
""" | ||
Route for GET requests to the edit page. | ||
Displays a form users can fill out to edit an existing record. | ||
""" | ||
doc = db.exampleapp.find_one({"_id": ObjectId(mongoid)}) | ||
return render_template('edit.html', mongoid=mongoid, doc=doc) # render the edit template | ||
|
||
|
||
@app.route('/edit/<mongoid>', methods=['POST']) | ||
def edit_post(mongoid): | ||
""" | ||
Route for POST requests to the edit page. | ||
Accepts the form submission data for the specified document and updates the document in the database. | ||
""" | ||
name = request.form['fname'] | ||
message = request.form['fmessage'] | ||
|
||
doc = { | ||
# "_id": ObjectId(mongoid), | ||
"name": name, | ||
"message": message, | ||
"created_at": datetime.datetime.utcnow() | ||
} | ||
|
||
db.exampleapp.update_one( | ||
{"_id": ObjectId(mongoid)}, # match criteria | ||
{ "$set": doc } | ||
) | ||
|
||
return redirect(url_for('read')) # tell the browser to make a request for the /read route | ||
|
||
|
||
@app.route('/delete/<mongoid>') | ||
def delete(mongoid): | ||
""" | ||
Route for GET requests to the delete page. | ||
Deletes the specified record from the database, and then redirects the browser to the read page. | ||
""" | ||
db.exampleapp.delete_one({"_id": ObjectId(mongoid)}) | ||
return redirect(url_for('read')) # tell the web browser to make a request for the /read route. | ||
|
||
@app.route('/webhook', methods=['POST']) | ||
def webhook(): | ||
""" | ||
GitHub can be configured such that each time a push is made to a repository, GitHub will make a request to a particular web URL... this is called a webhook. | ||
This function is set up such that if the /webhook route is requested, Python will execute a git pull command from the command line to update this app's codebase. | ||
You will need to configure your own repository to have a webhook that requests this route in GitHub's settings. | ||
Note that this webhook does do any verification that the request is coming from GitHub... this should be added in a production environment. | ||
""" | ||
# run a git pull command | ||
process = subprocess.Popen(["git", "pull"], stdout=subprocess.PIPE) | ||
pull_output = process.communicate()[0] | ||
# pull_output = str(pull_output).strip() # remove whitespace | ||
process = subprocess.Popen(["chmod", "a+x", "flask.cgi"], stdout=subprocess.PIPE) | ||
chmod_output = process.communicate()[0] | ||
# send a success response | ||
response = make_response('output: {}'.format(pull_output), 200) | ||
response.mimetype = "text/plain" | ||
return response | ||
|
||
@app.errorhandler(Exception) | ||
def handle_error(e): | ||
""" | ||
Output any errors - good for debugging. | ||
""" | ||
return render_template('error.html', error=e) # render the edit template | ||
|
||
|
||
if __name__ == "__main__": | ||
#import logging | ||
#logging.basicConfig(filename='/home/ak8257/error.log',level=logging.DEBUG) | ||
app.run(debug = True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
|
||
# load the credentials from the .env file | ||
def get(): | ||
""" | ||
Load the configuration settings from the .env file. | ||
:returns: a dictionary of credentials and configuration settings | ||
""" | ||
# open the .env configuration file | ||
APP_ROOT = os.path.join(os.path.dirname(__file__)) # refers to application_top | ||
dotenv_path = os.path.join(APP_ROOT, '.env') | ||
# loop through each line and add to dictionary | ||
f = open(dotenv_path, encoding='utf_8') | ||
config = {} # empty dictionary | ||
for line in f: | ||
# split by = | ||
line=line.strip() # remove line break | ||
# remove any comment from the line | ||
if '#' in line: | ||
line = line[:line.find('#')] | ||
setting = line.split('=') # split key and value apart | ||
if len(setting) == 2: | ||
key, value = setting | ||
config[key] = value | ||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
MONGO_HOST=your_db_host_server_name | ||
MONGO_USER=your_db_username | ||
MONGO_PASSWORD=your_db_password | ||
MONGO_DBNAME=your_db_name | ||
FLASK_APP=app.py | ||
FLASK_ENV=development | ||
GITHUB_SECRET=your_github_secret | ||
GITHUB_REPO=https://github.com/your-repository-url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
sys.path.insert(0, '/misc/linux/centos7/x86_64/local/stow/python-3.6/lib/python3.6/site-packages/') | ||
from wsgiref.handlers import CGIHandler | ||
from app import app | ||
CGIHandler().run(app) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Flask-MongoDB Web App | ||
|
||
In this assignment you will create a web app that relies upon a MongoDB database. | ||
|
||
## Example app | ||
|
||
An example web app has been included in this repository for your reference - see [how to setup and run that example web app](./setup.md). | ||
|
||
## Getting started | ||
|
||
It is **highly** recommended that you start by [setting up the example app](./setup.md). Get this example up-and-running before modifying the code in any way. | ||
|
||
To speed up development, you may want to have two copies of the example app running: one locally on your own computer and one on the **i6** web server. The example app setup instructions contain some guidance for setting up both remote and local instances of the app. | ||
|
||
## Requirements | ||
|
||
### Basic requirements | ||
|
||
You will create a web app that must... | ||
|
||
1. be written in Python, using [flask](https://flask.palletsprojects.com/en/1.1.x/) and [pymongo](https://pymongo.readthedocs.io/en/stable/index.html). | ||
1. be deployed (i.e. published) to NYU CS Department's web server and MongoDB server, **i6**.cims.nyu.edu and **class-mongodb**.cims.nyu.edu, respectively. | ||
1. allow the user to interact with data from the database in an intuitive and effortless manner, not requiring the user to understand any technical details of computer programming or databases. | ||
1. involve each of the basic operations of **CRUD** on documents in the database, triggered by user interactions. | ||
1. be well-designed with a clear consistency of design from one web page to the next. | ||
1. represent an amount of effort appropriate for an assignment of this duration and number of developers. | ||
1. do something useful and/or interesting. | ||
|
||
### Documentation requirements | ||
|
||
Delete the contents of the `README.md` file and replace with a well-written, nicely-formatted Markdown document describing your app. Include at least the following: | ||
|
||
- the title of your app | ||
- a simple description of your app | ||
- a link to the deployed copy of your app | ||
- the full names, NYU Net IDs, and links to GitHub accounts of any collaborators with whom you worked on this app | ||
|
||
## Submit your work | ||
|
||
Use Visual Studio Code to perform git `stage`, `commit` and `push` actions to submit. These actions are all available as menu items in Visual Studio Code's Source Control panel. | ||
|
||
1. Type a short note about what you have done to the files in the `Message` area, and then type `Command-Enter` (Mac) or `Control-Enter` (Windows) to perform git `stage` and `commit` actions. | ||
1. Click the `...` icon next to the words, "Source Control" and select "Push" to perform the git `push` action. This will upload your work to your repository on GitHub.com. | ||
|
||
![Pushing work in Visual Studio Code](./images/vscode_stage_commit_push.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
blinker==1.4 | ||
click==7.1.2 | ||
Flask==1.1.2 | ||
Flask-DebugToolbar==0.11.0 | ||
itsdangerous==1.1.0 | ||
Jinja2==2.11.3 | ||
MarkupSafe==1.1.1 | ||
pymongo==3.11.3 | ||
python-dotenv==0.16.0 | ||
Werkzeug==1.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Flask-MongoDB Example Web App | ||
|
||
A simple example of a web app using [pymongo](https://pymongo.readthedocs.io/en/stable/index.html) to interact with a MongoDB database. | ||
|
||
It is possible to run this app remotely or locally. Instructions are included for each. | ||
|
||
## Run locally | ||
|
||
To run this app locally, first clone this repository to your local machine... | ||
|
||
`git clone url-to-this-repository` | ||
|
||
... and then do the following: | ||
|
||
### Set up a Python virtual environment | ||
|
||
This command creates a new virtual environment with the name `.venv`: | ||
|
||
```bash | ||
python3 -m venv .venv | ||
``` | ||
|
||
#### Activate the virtual environment | ||
|
||
To activate the virtual environment named `.venv`... | ||
|
||
On Mac: | ||
|
||
```bash | ||
source .venv/bin/activate | ||
``` | ||
|
||
On Windows: | ||
|
||
```bash | ||
.venv\Scripts\activate.bat | ||
``` | ||
|
||
#### Install the dependencies into the virtual environment | ||
|
||
The 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. | ||
|
||
```bash | ||
pip3 install -r requirements.txt | ||
``` | ||
|
||
### Set up a local MongoDB database server | ||
|
||
If running this app locally, you will not be able to connect to the NYU CS Department's MongoDB server. So you must have your app connect to either a cloud hosted database server, such as [MongoDB Atlas](https://www.mongodb.com/cloud/atlas), or download [MongoDB Community Server](https://www.mongodb.com/try/download/community) and run a local database server on your own machine. | ||
|
||
### Run the app | ||
|
||
1. define two environment variables from the command line: on Mac, use the commands: `export FLASK_APP=app.py` and `export FLASK_ENV=development`; on Windows, use `set FLASK_APP=app.py` and `set FLASK_ENV=development`. | ||
1. copy the file named `env.example` into a new file named `.env`, and enter your own MongoDB database connection credentials into that file where indicated. | ||
1. 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. | ||
1. in some cases, the command `flask` will not be found when attempting `flask run`... you can alternatively launch it with `python3 -m flask run --host=0.0.0.0 --port=10000`. | ||
|
||
## Host on a web server | ||
|
||
The following steps outline how to host this application on NYU's **i6**.cims.nyu.edu web server. Other servers may vary. | ||
|
||
1. Familiarize yourself with web hosting steps on a CIMS server from the link: https://cims.nyu.edu/webapps/content/systems/userservices/webhosting. | ||
1. remotely log into the server using `ssh`. | ||
1. navigate into your web server account's `public_html` directory using `cd public_html`. | ||
1. clone this repository with `git clone url-to-this-repository`. | ||
1. navigate into the directory that was created by the clone operation. | ||
1. copy the file named `env.example` into a new file named `.env` (using `cp env.example .env`). | ||
1. edit the `.env` file using `emacs .env`, and enter your own MongoDB database connection credentials into that file where indicated. Save the changes within emacs by typing `Control-x` then `Control-s`. Exit emacs by typing, `Control-x` then `Control-c`. | ||
1. Make the files named `flask.cgi` executable by all with the command, `chmod a+x flask.cgi`. | ||
1. Your app should now be live on the web at https://i6.cims.nyu.edu/~$USER/$flask-app-directory/flask.cgi, where `$USER` is replaced with your own **i6** username and `$flask-app-directory` is replaced with the name of the sub-directory within `public_html` where your flask app code resides. Visit that address in your preferred web browser. | ||
|
||
## Continuous deployment | ||
|
||
While not required, it is possible to automatically update a copy of this web app anytime new changes to the code are pushed to GitHub. Such an automatic update of a deployed web app is known as "continuous deployment". | ||
|
||
Each repository on GitHub has a set of Settings for Webhooks. In those settings, it is possible to enter a "Payload URL" - GitHub will automatically issue an HTTP POST request to any URL you place there. The example web app code has a route designed to accept a webhook request from GitHub. That route automatically perform a `git pull` operation on the app's source code repository to update the code each time such a webhook request occurs. | ||
|
||
![Webhook settings](./images/webhook_settings.png) | ||
|
||
If attempting to test this webhook technique on a local instance of the web app, GitHub will not be able to make requests to your local machine. To solve this, is possible to use a tool such as [ngrok](https://ngrok.com/) to provide a public URL that forwards requests to your local machine. In such a scenario, with ngrok installed, you would set up ngrok to forward all HTTP requests to port `5000` of your local machine with the command, `ngrok http 5000`. Then enter the appropriate public ngrok address - something like `https://7ccd453a429f.ngrok.io/webhook/` - into the GitHub webhook "Payload URL" setting. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.container { | ||
border: 2px solid; | ||
width: 50%; | ||
margin: 0 auto; | ||
} | ||
|
||
header, | ||
footer, | ||
main { | ||
padding: 20px; | ||
} | ||
|
||
header, | ||
main { | ||
border-bottom: 2px solid; | ||
margin-bottom: 5px; | ||
} | ||
|
||
p.post { | ||
font-size: 12px; | ||
} | ||
|
||
footer { | ||
margin-bottom: 5px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Flask-MongoDB Example App</title> | ||
<link | ||
rel="stylesheet" | ||
href="{{ url_for('static', filename='css/style.css') }}" | ||
/> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<header> | ||
<h1>Flask-MongoDB Example App</h1> | ||
<p> | ||
<a href="{{ url_for('home')}}">Home</a> | | ||
<a href="{{ url_for('read')}}">All posts</a> | | ||
<a href="{{ url_for('create')}}">Create a post</a> | ||
</p> | ||
</header> | ||
<main>{% block container %} {% endblock %}</main> | ||
<footer> | ||
<p> | ||
The source code for this example app is | ||
<a href="https://github.com/nyu-database-design/flask-mongodb-example" | ||
>available on Github</a | ||
>. | ||
</p> | ||
</footer> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends 'base.html' %} {% block container %} | ||
<h2>Create</h2> | ||
<p>Create a new record in the MongoDB database collection.</p> | ||
<form method="POST" action="{{ url_for('create_post') }}"> | ||
<p>Your name: <input type="text" id="fname" name="fname" /><br /></p> | ||
<p> | ||
Message: | ||
<textarea type="text" id="fmessage" name="fmessage"></textarea> | ||
</p> | ||
<p> | ||
<a href="{{ url_for('read')}}">Cancel</a> | ||
<input type="submit" name="post-btn" value="Post" /> | ||
</p> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% extends 'base.html' %} {% block container %} | ||
<h2>Update</h2> | ||
<p>Edit a record in the MongoDB database collection.</p> | ||
<form method="POST" action="{{ url_for('edit_post', mongoid=mongoid) }}"> | ||
<p> | ||
Your name: | ||
<input type="text" id="fname" name="fname" value="{{doc.name}}" /><br /> | ||
</p> | ||
<p> | ||
Message: | ||
<textarea id="fmessage" name="fmessage">{{doc.message}}</textarea> | ||
</p> | ||
<p> | ||
<a href="{{ url_for('read')}}">Cancel</a> | ||
<input type="submit" name="post-btn" value="Save" /> | ||
</p> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends 'base.html' %} {% block container %} | ||
<h2>Uh oh!</h2> | ||
<p> | ||
Unfortunately, it seems that we have encountered an error... and here it is: | ||
</p> | ||
<code> {{error}} </code> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block container %} | ||
<h2>Welcome!</h2> | ||
<p>Welcome to the Flask app. This is the home page. Here are a few links to example pages you might find interesting. | ||
<ul> | ||
<li><a href="{{ url_for('read')}}">a page that displays information pulled from a MongoDB database collection</a></li> | ||
<li><a href="{{ url_for('create')}}">a page with a form you can submit to create a new record in a MongoDB collection</a></li> | ||
</ul> | ||
</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block container %} | ||
<h2>Read</h2> | ||
<p>This page shows information pulled from a MongoDB database collection. | ||
|
||
{% for doc in docs %} | ||
<div> | ||
<hr class="solid"> | ||
<p class="post"> | ||
Posted by {{doc.name}} at {{ doc.created_at.strftime("%H:%M on %d %B %Y") }} | ||
</br> | ||
<a href="{{ url_for('edit',mongoid=doc._id)}}">Edit</a> | <a href="{{ url_for('delete',mongoid=doc._id)}}">Delete</a> | ||
</br> | ||
</p> | ||
<p> | ||
{{ doc.message }} | ||
</p> | ||
|
||
</div> | ||
{%endfor%} | ||
</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<mxfile host="Electron" modified="2021-03-12T02:07:49.753Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/14.4.3 Chrome/87.0.4280.141 Electron/11.3.0 Safari/537.36" etag="rOM0WIjDAXv84Yz_Ju1U" version="14.4.3" type="device"><diagram id="mvmtVbBOe5ea1lltgGsm" name="Page-1">7VxbU9s6EP41eWzHt5jkEQKUh3KmU+hw+tRRbCXR4FiuLUNyfv3R1Y4tOTEQxwHCTAte67qXb1crWQN3slx9S0GyuMUhjAaOFa4G7uXAoT+uS38xylp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L27L3JO96Q13Le+fJ96DwVOXpdtf3p85sph94Lw6KK8JNeeXL1kPkRYXvmze+iJz3TwjCog0L8EtexJviYKa6Uqa3U+qNGbJjSZPX9MxTWw+7EmBno2bbeJtnaV527UXzKlrTRvPO+ZgTnBGmf+IWInnFDP+Gg+/ChDCjog5ZOtqxcBpCltjAs4G8hKXhE3z+xb2oIxRX7vKw640Gah8AxGvZP3tDR18zg19JWCr7wJkw4YlP+NWFOLIu3zkAOcFfmMLKsW80xO4Y2DHKUH4KokYonjOtK3kzgWh3Y0dKGCkFWSynUV53cDLTrfkRr26nLRPVo64iQF8P0PdqpxUMb2ep11TAQk83dkblLUlC88T9SEQUEtcjcaMYbDu/b9BfkqdxeX/ZlN2GyC3e7J12GFUg1zVWhpZJtK520NjgyVZaurSx37upmM4F7tFUah6gjancb9qGwTFsXDNGZUHFnEcgLexjly9jSpvxjIiV87FteIjCwl5nS3UHB3XTVbfm5MnJTrb6FHd8MEOhj+WFrGKRUt5r6179Dw==</diagram></mxfile> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.