Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

flask-login

How do I pass through the “next” URL with Flask and Flask-login?

December 25, 2023 by Tarik

If you need to specify a different action attribute in your form you can’t use the next parameter provided by Flask-Login. I’d recommend anyways to put the endpoint instead of the url into the url parameter since it is easier to validate. Here’s some code from the application I’m working on, maybe this can help … Read more

Categories python Tags flask, flask-login, forms, python Leave a comment

Testing Flask login and authentication?

December 24, 2023 by Tarik

The problem is different request contexts. In your normal Flask application, each request creates a new context which will be reused through the whole chain until creating the final response and sending it back to the browser. When you create and run Flask tests and execute a request (e.g. self.client.post(…)) the context is discarded after … Read more

Categories python Tags flask, flask-login, flask-security, python, unit-testing Leave a comment

ImportError: No module named flask.ext.login

September 9, 2023 by Tarik

If following does not work: from flask.ext.login import LoginManager try the following: from flask_login import LoginManager This is the new convention. To find the flask-login version, you can run the following command in terminal. Just change the name to know the version of other packages. pip show flask-login

Categories python Tags flask, flask-login, python Leave a comment

Flask-Login Password Reset

August 30, 2023 by Tarik

Base logic: Create reset password form with email field. When user submit form then you should: check this email in database generate undistinguished crypto random secret key (next just secret key) store this key, current timestamp and user identifier to cache or database send it to user email or sms When user apply secret key … Read more

Categories flask Tags flask, flask-login, flask-sqlalchemy Leave a comment

sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string

August 25, 2023 by Tarik

You are not using a valid URL in the connection string. Review the documentation on how the MySQL connection URLs need to be structured: http://docs.sqlalchemy.org/en/latest/dialects/mysql.html. Depending on the MySQL driver that you use the connection URL is different. For example, if you use pymysql, your URL should be: mysql+pymysql://<username>:<password>@<host>/<dbname>[?<options>]

Categories python Tags flask, flask-login, flask-migrate, flask-sqlalchemy, python Leave a comment

Flask permanent session: where to define them?

August 16, 2023 by Tarik

I’m surprised no on has answered this question. It seems like there should be some type of config variable SESSION_PERMANENT = True. But unfortunately there isn’t. As you mentioned this is the best way to do it. @app.before_request def make_session_permanent(): session.permanent = True

Categories python Tags cookies, flask, flask-login, python, session Leave a comment

Flask-Login check if user is authenticated without decorator

May 11, 2023 by Tarik

This is very simple in flask: from flask_login import current_user @app.route(…) def main_route(): if current_user.is_authenticated: return render_template(“main_for_user.html”) else: return render_template(“main_for_anonymous.html”) See the documentation on anonymous users.

Categories python Tags flask, flask-login, python Leave a comment

How to use g.user global in flask

March 18, 2023 by Tarik

g is a thread local and is per-request (See A Note On Proxies). The session is also a thread local, but in the default context is persisted to a MAC-signed cookie and sent to the client. The problem that you are running into is that session is rebuilt on each request (since it is sent … Read more

Categories python Tags flask, flask-login, jinja2, python Leave a comment

flask-login: can’t understand how it works

February 3, 2023 by Tarik

Flask-login doesn’t actually have a user backend, it just handles the session machinery to help you login and logout users. You have to tell it (by decorating methods), what represents a user and it is also up to you to figure out how to know if a user is “active” or not (since being “active” … Read more

Categories python Tags flask-login, mysql, python Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa