Skip to content

Commit 1719846

Browse files
committed
new flask examples
1 parent a6feea0 commit 1719846

16 files changed

+671
-91
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ at runtime when an
1616
that accepts POSTs.
1717

1818

19-
These topics are also useful while reading the `BadRequest` examples:
19+
These subjects go along with the `BadRequest` code examples:
2020

2121
* [web development](/web-development.html) and [web design](/web-design.html)
2222
* [Flask](/flask.html) and [web framework](/web-frameworks.html) concepts

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

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,69 @@ def create_app(config):
316316
```
317317

318318

319-
## Example 5 from flask-bookshelf
319+
## Example 5 from flask-bones
320+
[flask-bones](https://github.com/cburmeister/flask-bones)
321+
([demo](http://flask-bones.herokuapp.com/))
322+
is large scale [Flask](/flask.html) example application built
323+
with [Blueprints](https://flask.palletsprojects.com/en/1.1.x/blueprints/)
324+
([example Blueprint code](/flask-blueprints-blueprint-examples.html)).
325+
This project is provided as open source under the
326+
[MIT license](https://github.com/cburmeister/flask-bones/blob/master/LICENSE).
327+
328+
[**flask-bones / app / __init__.py**](https://github.com/cburmeister/flask-bones/blob/master/app/./__init__.py)
329+
330+
```python
331+
# __init__.py
332+
import time
333+
334+
~~from flask import Flask, g, render_template, request
335+
import arrow
336+
import requests
337+
338+
from app import config
339+
from app.assets import assets
340+
from app.auth import auth
341+
from app.commands import create_db, drop_db, populate_db, recreate_db
342+
from app.database import db
343+
from app.extensions import lm, travis, mail, migrate, bcrypt, babel, rq, limiter
344+
from app.user import user
345+
from app.utils import url_for_other_page
346+
347+
348+
def create_app(config=config.base_config):
349+
~~ app = Flask(__name__)
350+
app.config.from_object(config)
351+
352+
register_extensions(app)
353+
register_blueprints(app)
354+
register_errorhandlers(app)
355+
register_jinja_env(app)
356+
register_commands(app)
357+
358+
def get_locale():
359+
return request.accept_languages.best_match(config.SUPPORTED_LOCALES)
360+
361+
if babel.locale_selector_func is None:
362+
babel.locale_selector_func = get_locale
363+
364+
@app.before_request
365+
def before_request():
366+
g.request_start_time = time.time()
367+
g.request_time = lambda: '%.5fs' % (time.time() - g.request_start_time)
368+
g.pjax = 'X-PJAX' in request.headers
369+
370+
@app.route('/', methods=['GET'])
371+
def index():
372+
return render_template('index.html')
373+
374+
375+
376+
## ... source file continues with no further Flask examples...
377+
378+
```
379+
380+
381+
## Example 6 from flask-bookshelf
320382
[flask-bookshelf](https://github.com/damyanbogoev/flask-bookshelf) is the
321383
example [Flask](/flask.html) application that developers create when
322384
going through
@@ -368,7 +430,7 @@ def get_lang_code(endpoint, values):
368430
```
369431

370432

371-
## Example 6 from flaskex
433+
## Example 7 from flaskex
372434
[Flaskex](https://github.com/anfederico/Flaskex) is a working example
373435
[Flask](/flask.html) web application intended as a base to build your
374436
own applications upon. The application comes with pre-built sign up, log in
@@ -421,7 +483,7 @@ def logout():
421483
```
422484

423485

424-
## Example 7 from Flask-HTTPAuth
486+
## Example 8 from Flask-HTTPAuth
425487
[Flask-HTTPAuth](https://github.com/miguelgrinberg/Flask-HTTPAuth)
426488
([documentation](https://flask-httpauth.readthedocs.io/en/latest/)
427489
and
@@ -477,7 +539,7 @@ class HTTPAuthTestCase(unittest.TestCase):
477539
```
478540

479541

480-
## Example 8 from flask-phone-input
542+
## Example 9 from flask-phone-input
481543
[flask-phone-input](https://github.com/miguelgrinberg/flask-phone-input)
482544
is an example application that ties together the
483545
[intTellInput.js](https://github.com/jackocnr/intl-tel-input)
@@ -529,7 +591,7 @@ def index():
529591
```
530592

531593

532-
## Example 9 from flaskSaaS
594+
## Example 10 from flaskSaaS
533595
[flaskSaas](https://github.com/alectrocute/flaskSaaS) is a boilerplate
534596
starter project to build a software-as-a-service (SaaS) web application
535597
in [Flask](/flask.html), with [Stripe](/stripe.html) for billing. The
@@ -578,7 +640,7 @@ from app.models import User
578640
```
579641

580642

581-
## Example 10 from Flask-SocketIO
643+
## Example 11 from Flask-SocketIO
582644
[Flask-SocketIO](https://github.com/miguelgrinberg/Flask-SocketIO)
583645
([PyPI package information](https://pypi.org/project/Flask-SocketIO/),
584646
[official tutorial](https://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent)
@@ -689,7 +751,7 @@ if __name__ == '__main__':
689751
```
690752

691753

692-
## Example 11 from Flask-User
754+
## Example 12 from Flask-User
693755
[Flask-User](https://github.com/lingthio/Flask-User)
694756
([PyPI information](https://pypi.org/project/Flask-User/)
695757
and
@@ -772,7 +834,7 @@ class UserManager(UserManager__Settings, UserManager__Utils, UserManager__Views)
772834
```
773835

774836

775-
## Example 12 from Flask-VueJs-Template
837+
## Example 13 from Flask-VueJs-Template
776838
[Flask-VueJs-Template](https://github.com/gtalarico/flask-vuejs-template)
777839
([demo site](https://flask-vuejs-template.herokuapp.com/))
778840
is a minimal [Flask](/flask.html) boilerplate starter project that
@@ -813,7 +875,7 @@ def index_client():
813875
```
814876

815877

816-
## Example 13 from Flasky
878+
## Example 14 from Flasky
817879
[Flasky](https://github.com/miguelgrinberg/flasky) is a wonderful
818880
example application by
819881
[Miguel Grinberg](https://github.com/miguelgrinberg) that he builds
@@ -877,7 +939,7 @@ def create_app(config_name):
877939
```
878940

879941

880-
## Example 14 from Datadog Flask Example App
942+
## Example 15 from Datadog Flask Example App
881943
The [Datadog Flask example app](https://github.com/DataDog/trace-examples/tree/master/python/flask)
882944
contains many examples of the [Flask](/flask.html) core functions
883945
available to a developer using the [web framework](/web-frameworks.html).
@@ -938,7 +1000,7 @@ def before_request():
9381000
```
9391001

9401002

941-
## Example 15 from keras-flask-deploy-webapp
1003+
## Example 16 from keras-flask-deploy-webapp
9421004
The
9431005
[keras-flask-deploy-webapp](https://github.com/mtobeiyf/keras-flask-deploy-webapp)
9441006
project combines the [Flask](/flask.html) [web framework](/web-frameworks.html)
@@ -1002,7 +1064,7 @@ def model_predict(img, model):
10021064
```
10031065

10041066

1005-
## Example 16 from sandman2
1067+
## Example 17 from sandman2
10061068
[sandman2](https://github.com/jeffknupp/sandman2)
10071069
([project documentation](https://sandman2.readthedocs.io/en/latest/)
10081070
and
@@ -1083,7 +1145,7 @@ def get_app(
10831145
```
10841146

10851147

1086-
## Example 17 from Science Flask
1148+
## Example 18 from Science Flask
10871149
[Science Flask](https://github.com/danielhomola/science_flask)
10881150
is a [Flask](/flask.html)-powered web application for online
10891151
scientific research tools. The project was built as a template
@@ -1152,7 +1214,7 @@ def create_celery_app():
11521214
```
11531215

11541216

1155-
## Example 18 from tedivms-flask
1217+
## Example 19 from tedivms-flask
11561218
[tedivm's flask starter app](https://github.com/tedivm/tedivms-flask) is a
11571219
base of [Flask](/flask.html) code and related projects such as
11581220
[Celery](/celery.html) which provides a template to start your own
@@ -1281,7 +1343,7 @@ def create_app(extra_config_settings={}):
12811343
```
12821344

12831345

1284-
## Example 19 from trape
1346+
## Example 20 from trape
12851347
[trape](https://github.com/jofpin/trape) is a research tool for tracking
12861348
people's activities that are logged digitally. The tool uses
12871349
[Flask](/flask.html) to create a web front end to view aggregated data

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ from [requests](/flask-globals-request-examples.html) and responses for
1818
Flask web applications.
1919

2020

21-
These topics are also useful while reading the `Headers` examples:
21+
You should read up on these subjects along with these `Headers` examples:
2222

2323
* [web development](/web-development.html) and [web design](/web-design.html)
2424
* [Flask](/flask.html) and [web framework](/web-frameworks.html) concepts

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The `ImmutableDict` class wraps a
1616
so that values cannot be modified after initially being set.
1717

1818

19-
These subjects go along with the `ImmutableDict` code examples:
19+
You should read up on these subjects along with these `ImmutableDict` examples:
2020

2121
* [web development](/web-development.html) and [web design](/web-design.html)
2222
* [Flask](/flask.html) and [web framework](/web-frameworks.html) concepts

content/pages/examples/flask/flask-blueprints-blueprint.markdown

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,33 @@ def about():
272272
```
273273

274274

275-
## Example 4 from flask-bookshelf
275+
## Example 4 from flask-bones
276+
[flask-bones](https://github.com/cburmeister/flask-bones)
277+
([demo](http://flask-bones.herokuapp.com/))
278+
is large scale [Flask](/flask.html) example application built
279+
with [Blueprints](https://flask.palletsprojects.com/en/1.1.x/blueprints/)
280+
([example Blueprint code](/flask-blueprints-blueprint-examples.html)).
281+
This project is provided as open source under the
282+
[MIT license](https://github.com/cburmeister/flask-bones/blob/master/LICENSE).
283+
284+
[**flask-bones / app / auth / __init__.py**](https://github.com/cburmeister/flask-bones/blob/master/app/auth/__init__.py)
285+
286+
```python
287+
# __init__.py
288+
~~from flask import Blueprint
289+
290+
~~auth = Blueprint('auth', __name__, template_folder='templates')
291+
292+
from . import views
293+
294+
295+
296+
## ... source file continues with no further Blueprint examples...
297+
298+
```
299+
300+
301+
## Example 5 from flask-bookshelf
276302
[flask-bookshelf](https://github.com/damyanbogoev/flask-bookshelf) is the
277303
example [Flask](/flask.html) application that developers create when
278304
going through
@@ -323,7 +349,7 @@ def create_author():
323349
```
324350

325351

326-
## Example 5 from Flask-Bootstrap
352+
## Example 6 from Flask-Bootstrap
327353
[flask-bootstrap](https://github.com/mbr/flask-bootstrap)
328354
([PyPI package information](https://pypi.org/project/Flask-Bootstrap/))
329355
makes it easier to use the [Bootstrap CSS framework](/bootstrap-css.html)
@@ -427,7 +453,7 @@ class Bootstrap(object):
427453
```
428454

429455

430-
## Example 6 from flask-debugtoolbar
456+
## Example 7 from flask-debugtoolbar
431457
[Flask Debug-toolbar](https://github.com/flask-debugtoolbar/flask-debugtoolbar)
432458
([documentation](https://flask-debugtoolbar.readthedocs.io/en/latest/)
433459
and
@@ -497,7 +523,7 @@ class DebugToolbarExtension(object):
497523
```
498524

499525

500-
## Example 7 from flask-restx
526+
## Example 8 from flask-restx
501527
[Flask RESTX](https://github.com/python-restx/flask-restx) is an
502528
extension that makes it easier to build
503529
[RESTful APIs](/application-programming-interfaces.html) into
@@ -549,7 +575,7 @@ def swagger_static(filename):
549575
```
550576

551577

552-
## Example 8 from Flask-WTF
578+
## Example 9 from Flask-WTF
553579
[Flask-WTF](https://github.com/lepture/flask-wtf)
554580
([project documentation](https://flask-wtf.readthedocs.io/en/stable/)
555581
and
@@ -657,7 +683,7 @@ def generate_csrf(secret_key=None, token_key=None):
657683
```
658684

659685

660-
## Example 9 from Flask-User
686+
## Example 10 from Flask-User
661687
[Flask-User](https://github.com/lingthio/Flask-User)
662688
([PyPI information](https://pypi.org/project/Flask-User/)
663689
and
@@ -764,7 +790,7 @@ class UserManager(UserManager__Settings, UserManager__Utils, UserManager__Views)
764790
```
765791

766792

767-
## Example 10 from Flask-VueJs-Template
793+
## Example 11 from Flask-VueJs-Template
768794
[Flask-VueJs-Template](https://github.com/gtalarico/flask-vuejs-template)
769795
([demo site](https://flask-vuejs-template.herokuapp.com/))
770796
is a minimal [Flask](/flask.html) boilerplate starter project that
@@ -796,7 +822,7 @@ import os
796822
```
797823

798824

799-
## Example 11 from Datadog Flask Example App
825+
## Example 12 from Datadog Flask Example App
800826
The [Datadog Flask example app](https://github.com/DataDog/trace-examples/tree/master/python/flask)
801827
contains many examples of the [Flask](/flask.html) core functions
802828
available to a developer using the [web framework](/web-frameworks.html).
@@ -843,7 +869,7 @@ def bp_after_request(response):
843869
```
844870

845871

846-
## Example 12 from tedivms-flask
872+
## Example 13 from tedivms-flask
847873
[tedivm's flask starter app](https://github.com/tedivm/tedivms-flask) is a
848874
base of [Flask](/flask.html) code and related projects such as
849875
[Celery](/celery.html) which provides a template to start your own

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ FlaskBB is provided as open source
5050
[under this license](https://github.com/flaskbb/flaskbb/blob/master/LICENSE).
5151

5252

53+
### flask-bones
54+
[flask-bones](https://github.com/cburmeister/flask-bones)
55+
([demo](http://flask-bones.herokuapp.com/))
56+
is large scale [Flask](/flask.html) example application built
57+
with [Blueprints](https://flask.palletsprojects.com/en/1.1.x/blueprints/)
58+
([example Blueprint code](/flask-blueprints-blueprint-examples.html)).
59+
This project is provided as open source under the
60+
[MIT license](https://github.com/cburmeister/flask-bones/blob/master/LICENSE).
61+
62+
5363
### Flaskex
5464
[Flaskex](https://github.com/anfederico/Flaskex) is a working example
5565
[Flask](/flask.html) web application intended as a base to build your

0 commit comments

Comments
 (0)