authenticate(functions to log in the user if their registration information is correct we also import the default usercreationform in the register(functionwe check whether or not we're responding to post request if we're notwe make an instance of usercreationform with no initial data if we're responding to post requestwe make an instance of usercreationform based on the submitted data we check that the data is valid --in this casethat the username has the appropriate charactersthe passwords matchand the user isn' trying to do anything malicious in their submission if the submitted data is validwe call the form' save(method to save the username and the hash of the password to the database the save(method returns the newly created user objectwhich we store in new_user when the user' information is savedwe log them inwhich is twostep processwe call authenticate(with the arguments new_user username and their password when they registerthe user is asked to enter two matching passwordsand because the form is validwe know the passwords match so we can use either one here we get the value associated with the 'password key in the form' post data if the username and password are correctthe method returns an authenticated user objectwhich we store in authenticated_user we then call the login(function with the request and authenticated_user objects zwhich creates valid session for the new user finallywe redirect the user to the home page where personalized greeting in the header tells them their registration was successful the register template the template for the registration page is similar to the login page be sure to save it in the same directory as login htmlregister html {extends "learning_logs/base html%{block content %{csrf_token %{form as_p }register {endblock content %we use the as_p method again so django will display all the fields in the form appropriatelyincluding any error messages if the form is not filled out correctly user accounts