diff --git a/README.md b/README.md index 1308bee..70ce44e 100644 --- a/README.md +++ b/README.md @@ -2539,11 +2539,11 @@ from flask import Flask, send_from_directory, render_template_string, request ```python app = Flask(__name__) -app.run() +app.run(host=None, debug=None) ``` -* **Starts the app on `'http://localhost:5000'`.** -* **A WSGI server like [Waitress](https://flask.palletsprojects.com/en/latest/deploying/waitress/) and a HTTP server such as [Nginx](https://flask.palletsprojects.com/en/latest/deploying/nginx/) are needed to run globally.** - +* **Starts the app at `'http://localhost:5000'`. Use `'host="0.0.0.0"'` to run externally.** +* **Install a WSGI server like [Waitress](https://flask.palletsprojects.com/en/latest/deploying/waitress/) and a HTTP server such as [Nginx](https://flask.palletsprojects.com/en/latest/deploying/nginx/) for better security.** +* **Debug mode restarts the app whenever script changes and displays errors in the browser.** ### Static Request ```python @@ -2558,18 +2558,19 @@ def serve_file(filename): def serve_html(sport): return render_template_string('
app = Flask(__name__)
-app.run()
+app.run(host=None, debug=None)
'http://localhost:5000'
.'http://localhost:5000'
. Use 'host="0.0.0.0"'
to run externally.@app.route('/img/<path:filename>')
def serve_file(filename):
@@ -2096,18 +2097,17 @@ app.run()
'render_template()'
accepts filename of a template stored in 'templates' directory.'abort(<int>)'
and to redirect use 'redirect(<url>)'
.'request.args[<str>]'
returns parameter from the query string (URL part after the ?).'session[key] = value'
to store session data like username, etc.@app.route('/<sport>/odds', methods=['POST'])
+REST Request
@app.post('/<sport>/odds')
def serve_json(sport):
team = request.form['team']
return {'team': team, 'odds': [2.09, 3.74, 3.68]}
-
-- To get a parameter from the query string (part after the ?) use
'request.args.get(<str>)'
.
-
-Test:
# $ pip3 install requests
+Starts the app in its own thread and queries it with a post request:
# $ pip3 install requests
>>> import threading, requests
>>> threading.Thread(target=app.run, daemon=True).start()
>>> url = 'http://localhost:5000/football/odds'
@@ -2934,7 +2934,7 @@ $ pyinstaller script.py --add-data '<path>:.'
diff --git a/pdf/index_for_pdf.html b/pdf/index_for_pdf.html
index 72dd72b..9b80128 100644
--- a/pdf/index_for_pdf.html
+++ b/pdf/index_for_pdf.html
@@ -115,7 +115,7 @@
recursion, 13
reduce function, 11, 31
regular expressions, 5-6
-requests library, 35, 36
+requests library, 35, 36
S