Open zipperer opened 8 months ago
Examples: command line interface
Example: web interface (local webpage; not hosted on public web)
See files in directory flask_app
$ cd flask_app
$ python3 -m venv .venv
$ source .venv/bin/activate
(venv) $ python3 -m pip install flask
(venv) $ python3 -m pip install psycopg2-binary
(venv) $ flask run --port 5002
Then in a web browser visit localhost:5002/timestamped_verses/table/3192
, in general localhost:5002/timestamped_verses/table/<message-id>
https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iii-web-forms https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
https://www.psycopg.org/docs/install.html#quick-install https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table https://www.w3schools.com/html/tryit.asp?filename=tryhtml_table_cellpadding https://www.w3schools.com/html/html_table_padding_spacing.asp
See files in directory flask_app
Basic idea:
/timestamped_verses/table/<int:message_id>
(for development server localhost:5002/timestamped_verses/table/<int:message_id>
Example: web interface (local webpage; not hosted on public web) ... Then in a web browser visit localhost:5002/timestamped_verses/table/3192, in general >localhost:5002/timestamped_verses/table/
We can now view these pages on public web.
/etc/nginx/nginx.conf
http {
server {
...
+ location /grace_and_truth {
+ proxy_pass http://localhost:5002; # e.g. https://zipperer.dev/grace_and_truth/timestamped_verses/table/3194
+ proxy_redirect off;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
^ see https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux
5002 comes from flask run --port 5002
. TODO: use gunicorn
(or other production web server) as Miguel describes.
routes.py
- @app.route('/timestamped_verses/table/<int:message_id>', methods=['GET'])
+ @app.route('/grace_and_truth/timestamped_verses/table/<int:message_id>', methods=['GET'])
def get_timestamped_verses_table(message_id):
message_title = message_id_title(message_id)
results = message_id_timestamped_verses(message_id)
return render_template('timestamp_verse_table.html', message_id=message_id, message_title=message_title, results=results)
^ note that location /grace_and_truth
in nginx.conf
corresponds to @app.route('/grace_and_truth/...)
For example: