flask_login_multi
Flask-Login with multiple models: User Model,Admin Model ...
#####1.setup Flask_Login #####2.import flask_login_multi
from flask import Flask
from flask_login_multi.login_manager import LoginManager
app=Flask(__name__)
login_manager = LoginManager(app)
login_manager.blueprint_login_views = {
'user': "user.user_login",
'admin': "admin.admin_login",
}
#####3.set buleprint
admin_app = Blueprint('admin', __name__, url_prefix="/admin")
user_app = Blueprint('user', __name__, url_prefix="/user")
#####4. model add user_loader
@login_manager.user_loader
def load_user(id, endpoint='user'):
if endpoint == 'admin':
return Admin.query.get(id)
else:
return User.query.get(id)
#####5. admin or user login
from app.libs.flask_login_multi import login_user
#user
user = User.query.filter_by(name=form.name.data).first()
login_user(user,remember=True)
#admin
user = Admin.query.filter_by(name=form.name.data).first()
login_user(admin)
#####6.admin login required
from app.libs.flask_login_multi import login_required,current_user
@admin_app.route('/index')
@login_required
def index():
print(current_user)
return 'admin.index'
Metadata
Release files for Flask-Login-Multi 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Flask_Login_Multi-0.1.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for Flask_Login_Multi-0.1.2-py2.py3-none-any.whl |
Release files / Flask_Login_Multi-0.1.2-py2.py3-none-any.whl
| Download URL | Flask_Login_Multi-0.1.2-py2.py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
de83372acd8f632a09d3f286976557cedc5eea042fc46259ec716acfc49cc443
|
|
BLAKE2b-256 checksum How to use checksums |
1930778210c22ae9c5aa018b24f3a8e4e55d97c133341a4ae998520207c52550
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6
|
Security for Flask-Login-Multi 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.