Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7794055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:40:53+00:00 2026-06-01T22:40:53+00:00

Until django 1.2.5 i could use the following code to create a user for

  • 0

Until django 1.2.5 i could use the following code to create a user for testing and then log it in:

class TestSomeLoginRequiredView(TestCase):
    urls = 'sonloop.tests.test_urls'

    def setUp(self):
        self.user = User.objects.create(username='testuser',password='some_password')


    def test_the_view(self):
        response = self.client.get('/test_view_url/')
        self.assertEqual(response.status_code,401)

        self.client.login(username='testuser',password='some_password')
        response = self.client.get('/test_view_url/')
        self.assertEqual(response.status_code,200)

Now using the same code with django 1.4 doesn’t work any more:

ValueError: Unknown password hashing algorithm ‘some_password’. Did you
specify it in the PASSWORD_HASHERS setting?

I understand this has to do with the new password hashing system. I do not use the PASSWORD_HASHERS setting, so Django should use some default.

Django docs are quite sparse about how to implement something like that now. In the testing section nothing has changed. And from the section about creating passwords and how to hash them, i could see that i could probably create a password like this:

self.user = User.objects.create(username='testuser')
self.user.set_password('some_password')

But that only raises this eception in the first line (when creating the user, not when assigning the password):

ValueError: Unknown password hashing algorithm ”. Did you
specify it in the PASSWORD_HASHERS setting?

This is some problem with django not accepting empty passwords, so i changed that to:

self.user = User.objects.create(username='testuser',password='!')
self.user.set_password('some_password')

And then try to log the user in like that:

login = self.client.login(username='testuser',password='some_password')
self.assertTrue(login)

Which now raises an AssertionError: False is not True sigh – i almost expected that…

My question now is: How can i create a user with a password, and log this user in with the django test client?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:40:54+00:00Added an answer on June 1, 2026 at 10:40 pm
    self.user = User.objects.create(username='testuser',password='!')
    self.user.set_password('some_password')
    self.user.save() # <--- You need this ;)
    

    OR: from here

    self.user = User.objects.create_user(username='user', email='email@example.com', password='pass')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running fabric (Django deployment to apache) and everything seems to work fine until
I have a Django-project which was running fine, until I made some changes I
I'm using Django/Python, but pseudo-code is definitely acceptable here. Working with some models that
I have a django application and until now I used sqLite as database backend.
So I'm creating a django app that allows a user to add a new
I'm using Django and Apache to serve webpages. My JavaScript code currently includes a
I'm trying to generate some pdf with django/PIL/Imaging and everything is good until I
I am following Heroku's tutorial to deploy a Django app: http://devcenter.heroku.com/articles/django#prerequisites . Everything is
Using django-social-auth to grab user data from facebook, it is returning a list of
I'm trying to use django, and mongoengine to provide the storage backend only with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.