I had to create basic authentication in my project(based on Pylons), and this is simple solution to do it.
First, you have to open your config/middleware.py. It’s necessary to import AuthBasicHandler: from paste.auth.basic import AuthBasicHandler.
Next step is find ‘app = PylonsApp()‘. Change this line to: ap = PylonsApp() and add after: app = AuthBasicHandler(ap, “My realm”, authfunc). Of course you need to create auth function, for example:
def authfunc(environ, username, password):
if username == 'myusername' and password == 'mypassword':
return True
else:
return False
Restart your application environment.
That’s it