[Answered ]-Django Testing Client POST Request, Getting 403 Error

1👍

After reading the Django testing documentation further, I learned that I can’t simply set the password of the User I created for testing directly using ‘password’: ‘pass123!’, but instead need to use .set_password(), as the password needs to be stored in a correctly hashed format.

Snippet of the relevant Django documentation below for anyone who runs into a similar issue as me in the future!:

Remember that if you want your test user to have a password, you can’t
set the user’s password by setting the password attribute directly –
you must use the set_password() function to store a correctly hashed
password. Alternatively, you can use the create_user() helper method
to create a new user with a correctly hashed password.

Leave a comment