Skip to content

Commit 21d7bbf

Browse files
committed
add additional flask examples
1 parent 51d10c3 commit 21d7bbf

9 files changed

+1142
-39
lines changed

content/pages/examples/flask/flask-app-flask.markdown

Lines changed: 129 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,63 @@ def logout():
356356
```
357357

358358

359-
## Example 6 from flask-phone-input
359+
## Example 6 from Flask-HTTPAuth
360+
[Flask-HTTPAuth](https://github.com/miguelgrinberg/Flask-HTTPAuth)
361+
([documentation](https://flask-httpauth.readthedocs.io/en/latest/)
362+
and
363+
[PyPI package information](https://pypi.org/project/Flask-HTTPAuth/))
364+
is a [Flask](/flask.html) framework extension that creates
365+
Basic and Digest HTTP authentication for routes. This project
366+
is primarily built and maintained by
367+
[Miguel Grinberg](https://blog.miguelgrinberg.com/). It is provided
368+
as open source under the
369+
[MIT license](https://github.com/miguelgrinberg/Flask-HTTPAuth/blob/master/LICENSE).
370+
371+
[**Flask-HTTPAuth / tests / test_basic_get_password.py**](https://github.com/miguelgrinberg/Flask-HTTPAuth/blob/master/./tests/test_basic_get_password.py)
372+
373+
```python
374+
# test_basic_get_password.py
375+
import unittest
376+
import base64
377+
~~from flask import Flask
378+
from flask_httpauth import HTTPBasicAuth
379+
380+
381+
class HTTPAuthTestCase(unittest.TestCase):
382+
def setUp(self):
383+
~~ app = Flask(__name__)
384+
app.config['SECRET_KEY'] = 'my secret'
385+
386+
basic_auth = HTTPBasicAuth()
387+
388+
@basic_auth.get_password
389+
def get_basic_password(username):
390+
if username == 'john':
391+
return 'hello'
392+
elif username == 'susan':
393+
return 'bye'
394+
else:
395+
return None
396+
397+
@app.route('/')
398+
def index():
399+
return 'index'
400+
401+
@app.route('/basic')
402+
@basic_auth.login_required
403+
def basic_auth_route():
404+
return 'basic_auth:' + basic_auth.username()
405+
406+
self.app = app
407+
self.basic_auth = basic_auth
408+
409+
410+
## ... source file continues with no further Flask examples...
411+
412+
```
413+
414+
415+
## Example 7 from flask-phone-input
360416
[flask-phone-input](https://github.com/miguelgrinberg/flask-phone-input)
361417
is an example application that ties together the
362418
[intTellInput.js](https://github.com/jackocnr/intl-tel-input)
@@ -408,7 +464,7 @@ def index():
408464
```
409465

410466

411-
## Example 7 from flaskSaaS
467+
## Example 8 from flaskSaaS
412468
[flaskSaas](https://github.com/alectrocute/flaskSaaS) is a boilerplate
413469
starter project to build a software-as-a-service (SaaS) web application
414470
in [Flask](/flask.html), with [Stripe](/stripe.html) for billing. The
@@ -457,7 +513,7 @@ from app.models import User
457513
```
458514

459515

460-
## Example 8 from Flask-SocketIO
516+
## Example 9 from Flask-SocketIO
461517
[Flask-SocketIO](https://github.com/miguelgrinberg/Flask-SocketIO)
462518
([PyPI package information](https://pypi.org/project/Flask-SocketIO/),
463519
[official tutorial](https://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent)
@@ -568,7 +624,7 @@ if __name__ == '__main__':
568624
```
569625

570626

571-
## Example 9 from Flask-User
627+
## Example 10 from Flask-User
572628
[Flask-User](https://github.com/lingthio/Flask-User)
573629
([PyPI information](https://pypi.org/project/Flask-User/)
574630
and
@@ -651,7 +707,7 @@ class UserManager(UserManager__Settings, UserManager__Utils, UserManager__Views)
651707
```
652708

653709

654-
## Example 10 from Flask-VueJs-Template
710+
## Example 11 from Flask-VueJs-Template
655711
[Flask-VueJs-Template](https://github.com/gtalarico/flask-vuejs-template)
656712
([demo site](https://flask-vuejs-template.herokuapp.com/))
657713
is a minimal [Flask](/flask.html) boilerplate starter project that
@@ -692,7 +748,7 @@ def index_client():
692748
```
693749

694750

695-
## Example 11 from Flasky
751+
## Example 12 from Flasky
696752
[Flasky](https://github.com/miguelgrinberg/flasky) is a wonderful
697753
example application by
698754
[Miguel Grinberg](https://github.com/miguelgrinberg) that he builds
@@ -756,7 +812,7 @@ def create_app(config_name):
756812
```
757813

758814

759-
## Example 12 from Datadog Flask Example App
815+
## Example 13 from Datadog Flask Example App
760816
The [Datadog Flask example app](https://github.com/DataDog/trace-examples/tree/master/python/flask)
761817
contains many examples of the [Flask](/flask.html) core functions
762818
available to a developer using the [web framework](/web-frameworks.html).
@@ -817,7 +873,71 @@ def before_request():
817873
```
818874

819875

820-
## Example 13 from sandman2
876+
## Example 14 from keras-flask-deploy-webapp
877+
The
878+
[keras-flask-deploy-webapp](https://github.com/mtobeiyf/keras-flask-deploy-webapp)
879+
project combines the [Flask](/flask.html) [web framework](/web-frameworks.html)
880+
with the [Keras deep learning library](https://keras.io/) to provide
881+
an example image classifier that is easy to [deploy](/deployment.html).
882+
The application can be quckly run in a [Docker](/docker.html) container
883+
on your local development environment. The project is licensed under the
884+
[GNU General Public License v3.0](https://github.com/mtobeiyf/keras-flask-deploy-webapp/blob/master/LICENSE).
885+
886+
[**keras-flask-deploy-webapp / app.py**](https://github.com/mtobeiyf/keras-flask-deploy-webapp/blob/master/././app.py)
887+
888+
```python
889+
# app.py
890+
import os
891+
import sys
892+
893+
~~from flask import Flask, redirect, url_for, request, render_template, Response, jsonify, redirect
894+
from werkzeug.utils import secure_filename
895+
from gevent.pywsgi import WSGIServer
896+
897+
import tensorflow as tf
898+
from tensorflow import keras
899+
900+
from tensorflow.keras.applications.imagenet_utils import preprocess_input, decode_predictions
901+
from tensorflow.keras.models import load_model
902+
from tensorflow.keras.preprocessing import image
903+
904+
import numpy as np
905+
from util import base64_to_pil
906+
907+
908+
~~app = Flask(__name__)
909+
910+
911+
from keras.applications.mobilenet_v2 import MobileNetV2
912+
model = MobileNetV2(weights='imagenet')
913+
914+
print('Model loaded. Check http://127.0.0.1:5000/')
915+
916+
917+
MODEL_PATH = 'models/your_model.h5'
918+
919+
920+
921+
def model_predict(img, model):
922+
img = img.resize((224, 224))
923+
924+
x = image.img_to_array(img)
925+
x = np.expand_dims(x, axis=0)
926+
927+
x = preprocess_input(x, mode='tf')
928+
929+
preds = model.predict(x)
930+
return preds
931+
932+
933+
934+
935+
## ... source file continues with no further Flask examples...
936+
937+
```
938+
939+
940+
## Example 15 from sandman2
821941
[sandman2](https://github.com/jeffknupp/sandman2)
822942
([project documentation](https://sandman2.readthedocs.io/en/latest/)
823943
and
@@ -898,7 +1018,7 @@ def get_app(
8981018
```
8991019

9001020

901-
## Example 14 from tedivms-flask
1021+
## Example 16 from tedivms-flask
9021022
[tedivm's flask starter app](https://github.com/tedivm/tedivms-flask) is a
9031023
base of [Flask](/flask.html) code and related projects such as
9041024
[Celery](/celery.html) which provides a template to start your own

content/pages/examples/flask/flask-example-projects-code.markdown

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ JavaScript plugin with the
6363
library. flask-phone-input is provided as open source under the
6464
[MIT license](https://github.com/miguelgrinberg/flask-phone-input/blob/1a1c227c044474ce0fe133493d7f8b0fb8312409/LICENSE).
6565

66+
6667
### flaskSaaS
6768
[flaskSaas](https://github.com/alectrocute/flaskSaaS) is a boilerplate
6869
starter project to build a software-as-a-service (SaaS) web application
@@ -84,6 +85,17 @@ while teaching developers how to use [Flask](/flask.html) in
8485
is [open sourced under the MIT license](https://github.com/miguelgrinberg/flasky/blob/master/LICENSE).
8586

8687

88+
### Deploy Keras Model with Flask as Web App in 10 Minutes
89+
The
90+
[keras-flask-deploy-webapp](https://github.com/mtobeiyf/keras-flask-deploy-webapp)
91+
project combines the [Flask](/flask.html) [web framework](/web-frameworks.html)
92+
with the [Keras deep learning library](https://keras.io/) to provide
93+
an example image classifier that is easy to [deploy](/deployment.html).
94+
The application can be quckly run in a [Docker](/docker.html) container
95+
on your local development environment. The project is licensed under the
96+
[GNU General Public License v3.0](https://github.com/mtobeiyf/keras-flask-deploy-webapp/blob/master/LICENSE).
97+
98+
8799
### newspie
88100
[NewsPie](https://github.com/skamieniarz/newspie) is a minimalistic news
89101
aggregator created with [Flask](/flask.html) and the

content/pages/examples/flask/flask-extensions-plug-ins.markdown

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ mode. The project is provided as open source under
7878
[this license](https://github.com/flask-debugtoolbar/flask-debugtoolbar/blob/master/LICENSE).
7979

8080

81+
### Flask-HTTPAuth
82+
[Flask-HTTPAuth](https://github.com/miguelgrinberg/Flask-HTTPAuth)
83+
([documentation](https://flask-httpauth.readthedocs.io/en/latest/)
84+
and
85+
[PyPI package information](https://pypi.org/project/Flask-HTTPAuth/))
86+
is a [Flask](/flask.html) framework extension that creates
87+
Basic and Digest HTTP authentication for routes. This project
88+
is primarily built and maintained by
89+
[Miguel Grinberg](https://blog.miguelgrinberg.com/). It is provided
90+
as open source under the
91+
[MIT license](https://github.com/miguelgrinberg/Flask-HTTPAuth/blob/master/LICENSE).
92+
93+
8194
### Flask-Login
8295
[Flask-Login](https://github.com/maxcountryman/flask-login)
8396
([project documentation](https://flask-login.readthedocs.io/en/latest/)

0 commit comments

Comments
 (0)