Search code examples
python.htaccessflask.htpasswd

Python Flask to password protect website with .htaccess similar to PHP


My google search leads me to these articles 01 02

With 01 I don't know how to use it; recieving error

ImportError: No module named flask.ext.htpasswd

With 02, it seems to be incomplete.

So how can we protect website with .htaccess password similarly the way we do with PHP website?


Solution

  • Both those solutions are perfectly correct. For the first, as has already been established, you need to install the flask-htpasswd extension first:

    pip install flask-htpasswd
    

    For the second, you'll need to show your implementation. But basically, the method requires you to create a custom decorator which asks for the authentication. You can extend it further by storing a logged in user's credentials inside the sessions.