Python & HTML: Make user login to use website
I'm creating a website with a database search functionality, but I want to make the user login or create a account first to use the search functionality. How do I do this? And what 开发者_开发百科is the easiest way to carry the login session forward. I.E. the user only has to login once to do many searches.
Look at Web Frameworks for Python, and select one of the listed Popular Full-Stack Frameworks (Django, TurboGears, ...). Each framework provides its own session support.
SO discussions, for example choosing-a-web-application-framework-in-python, can help you choose one that meets your requirements.
If you're using Apache as your web server you can use the built-in Htaccess command line tools for user management: http://en.wikipedia.org/wiki/Htaccess
Htaccess is built-in to Apache and lets you manage users for PHP pages, CGI's (including Python), HTML pages, and others.
Here's a few example use-cases:
Initial setup:
a. copy 3 .ht* files (.htpasswords, .htgroups, .htaccess) into your document root (find templates of these files on the web).
b. add "AllowOverride Authconfig" into your apache conf file
Create new user ('root') when .htpasswords file does not exist:
$ htpasswd -c .htpasswords root
add a user named 'root':
$ htpasswd /Users/username/Sites/.htpasswords root
change password of user 'root':
$ htpasswd /Users/username/Sites/.htpasswords root
In PHP you can see who logged in via htaccess and get their password with:
$pass = $_SERVER['PHP_AUTH_PW']; // from htaccess
Htaccess is not super user-friendly, so feel free to update/improve my workflow
精彩评论