@@ -251,7 +251,111 @@ def configure_migrations(app):
251251```
252252
253253
254- ## Example 3 from flask-login
254+ ## Example 3 from flaskex
255+ [ Flaskex] ( https://github.com/anfederico/Flaskex ) is a working example
256+ [ Flask] ( /flask.html ) web application intended as a base to build your
257+ own applications upon. The application comes with pre-built sign up, log in
258+ and related screens, as well as a database backend. Flaskex is provided
259+ as open source under the
260+ [ MIT license] ( https://github.com/anfederico/Flaskex/blob/master/LICENSE.txt ) .
261+
262+ [ ** flaskex / app.py** ] ( https://github.com/anfederico/Flaskex/blob/master/././app.py )
263+
264+ ``` python
265+ # app.py
266+ # -*- coding: utf-8 -*-
267+
268+ from scripts import tabledef
269+ from scripts import forms
270+ from scripts import helpers
271+ ~~ from flask import Flask, redirect, url_for, render_template, request, session
272+ import json
273+ import sys
274+ import os
275+
276+ app = Flask(__name__ )
277+ app.secret_key = os.urandom(12 ) # Generic key for dev purposes only
278+
279+ # Heroku
280+ # from flask_heroku import Heroku
281+ # heroku = Heroku(app)
282+
283+ # ======== Routing =========================================================== #
284+ # -------- Login ------------------------------------------------------------- #
285+ @app.route (' /' , methods = [' GET' , ' POST' ])
286+ def login ():
287+ if not session.get(' logged_in' ):
288+ ~~ form = forms.LoginForm(request.form)
289+ ~~ if request.method == ' POST' :
290+ ~~ username = request.form[' username' ].lower()
291+ ~~ password = request.form[' password' ]
292+ if form.validate():
293+ if helpers.credentials_valid(username, password):
294+ session[' logged_in' ] = True
295+ session[' username' ] = username
296+ return json.dumps({' status' : ' Login successful' })
297+ return json.dumps({' status' : ' Invalid user/pass' })
298+ return json.dumps({' status' : ' Both fields required' })
299+ return render_template(' login.html' , form = form)
300+ user = helpers.get_user()
301+ return render_template(' home.html' , user = user)
302+
303+
304+ @app.route (" /logout" )
305+ def logout ():
306+ session[' logged_in' ] = False
307+ return redirect(url_for(' login' ))
308+
309+
310+ # -------- Signup ---------------------------------------------------------- #
311+ @app.route (' /signup' , methods = [' GET' , ' POST' ])
312+ def signup ():
313+ if not session.get(' logged_in' ):
314+ ~~ form = forms.LoginForm(request.form)
315+ ~~ if request.method == ' POST' :
316+ ~~ username = request.form[' username' ].lower()
317+ ~~ password = helpers.hash_password(request.form[' password' ])
318+ ~~ email = request.form[' email' ]
319+ if form.validate():
320+ if not helpers.username_taken(username):
321+ helpers.add_user(username, password, email)
322+ session[' logged_in' ] = True
323+ session[' username' ] = username
324+ return json.dumps({' status' : ' Signup successful' })
325+ return json.dumps({' status' : ' Username taken' })
326+ return json.dumps({' status' : ' User/Pass required' })
327+ return render_template(' login.html' , form = form)
328+ return redirect(url_for(' login' ))
329+
330+
331+ # -------- Settings ---------------------------------------------------------- #
332+ @app.route (' /settings' , methods = [' GET' , ' POST' ])
333+ def settings ():
334+ if session.get(' logged_in' ):
335+ ~~ if request.method == ' POST' :
336+ ~~ password = request.form[' password' ]
337+ if password != " " :
338+ password = helpers.hash_password(password)
339+ ~~ email = request.form[' email' ]
340+ helpers.change_user(password = password, email = email)
341+ return json.dumps({' status' : ' Saved' })
342+ user = helpers.get_user()
343+ return render_template(' settings.html' , user = user)
344+ return redirect(url_for(' login' ))
345+
346+
347+ # ======== Main ============================================================== #
348+ if __name__ == " __main__" :
349+ app.run(debug = True , use_reloader = True , host = " 0.0.0.0" )
350+
351+
352+ # # ... source file continues with no further request examples...
353+
354+
355+ ```
356+
357+
358+ ## Example 4 from flask-login
255359[ Flask-Login] ( https://github.com/maxcountryman/flask-login )
256360([ project documentation] ( https://flask-login.readthedocs.io/en/latest/ )
257361and [ PyPI package] ( https://pypi.org/project/Flask-Login/ ) )
@@ -560,7 +664,7 @@ def _secret_key(key=None):
560664```
561665
562666
563- ## Example 4 from flask-restx
667+ ## Example 5 from flask-restx
564668[ Flask RESTX] ( https://github.com/python-restx/flask-restx ) is an
565669extension that makes it easier to build
566670[ RESTful APIs] ( /application-programming-interfaces.html ) into
@@ -665,7 +769,7 @@ class marshal_with_field(object):
665769```
666770
667771
668- ## Example 5 from flask-sqlalchemy
772+ ## Example 6 from flask-sqlalchemy
669773[ flask-sqlalchemy] ( https://github.com/pallets/flask-sqlalchemy )
670774([ project documentation] ( https://flask-sqlalchemy.palletsprojects.com/en/2.x/ )
671775and
@@ -791,7 +895,7 @@ def _make_table(db):
791895```
792896
793897
794- ## Example 6 from Flask-WTF
898+ ## Example 7 from Flask-WTF
795899[Flask-WTF](https://github.com/lepture/flask-wtf)
796900([project documentation](https://flask-wtf.readthedocs.io/en/stable/)
797901and
@@ -953,7 +1057,7 @@ def generate_csrf(secret_key=None, token_key=None):
9531057```
9541058
9551059
956- ## Example 7 from flaskSaaS
1060+ ## Example 8 from flaskSaaS
9571061[flaskSaas](https://github.com/alectrocute/flaskSaaS) is a boilerplate
9581062starter project to build a software-as-a-service (SaaS) web application
9591063in [Flask](/flask.html), with [Stripe](/stripe.html) for billing. The
@@ -1006,7 +1110,7 @@ admin.add_view(FileAdmin(path, '/static/', name='Static'))
10061110```
10071111
10081112
1009- ## Example 8 from newspie
1113+ ## Example 9 from newspie
10101114[NewsPie](https://github.com/skamieniarz/newspie) is a minimalistic news
10111115aggregator created with [Flask](/flask.html) and the
10121116[News API](https://newsapi.org/).
@@ -1215,7 +1319,7 @@ if __name__ == '__main__':
12151319```
12161320
12171321
1218- ## Example 9 from sandman2
1322+ ## Example 10 from sandman2
12191323[sandman2](https://github.com/jeffknupp/sandman2)
12201324([project documentation](https://sandman2.readthedocs.io/en/latest/)
12211325and
0 commit comments