August 3, 2015

Howto Reset The Admin Password in Django

I keep needing to do this, darn it! I leave a project for a few months, possibly push it live, and then I go back to fire up the dev server but I simply cannot remember the password I used for admin during development.

Why don’t I use my stupid-development-password? I don’t know, but this seems to happen with some regularity.

Luckily, it is trivial to fix with a few lines at the python commandline:

Deep:/opt/webapps/invisible bruce$ ./ shell
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
Type "copyright", "credits" or "license" for more information.

IPython 0.7.2 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from django.contrib.auth.models import User

In [2]: users = User.objects.all()

In [3]: users
Out[3]: [<User: admin>]

In [4]: users[0].set_password('whatever');

In [5]: users[0].save()

That’s it, fire up the dev server again and your new password will get you in.


Share and Enjoy:
  • services sprite Howto Reset The Admin Password in Django
  • services sprite Howto Reset The Admin Password in Django
  • services sprite Howto Reset The Admin Password in Django
  • services sprite Howto Reset The Admin Password in Django
  • services sprite Howto Reset The Admin Password in Django
  • services sprite Howto Reset The Admin Password in Django
  • services sprite Howto Reset The Admin Password in Django
  • services sprite Howto Reset The Admin Password in Django

Related posts:

  1. Howto use Satchmo as an App I'm going to be using Satchmo to power the backend...
  2. Helpful Django utilities and links Two simple links which have been very helpful in doing...
  3. Speedy Django Development As I’ve mentioned before, I am building my own web...
  4. Top ten reasons to use Django for your web framework Django is pulling ahead of every other web framework I’ve...
  5. First use of the Django Magic Removal Last night I took a break from my most recent...

About Bruce Kroeze


  1. This infact did not work for me as is. But if I get the user object by explicit username, it worked. Maybe this is a bug. I will need to do some testing and report it…

    So your example did not work, but the following worked:

  2. Chris says:

    Thank you for posting such useful information! That was easy and it worked beautifully with Django 0.96.

    I was just about ready to bust out sha1sum and replace the hash in the MySQL database, but this was much better.

  3. Antony C says:

    Thank you :)

  4. Ben Chapman says:

    Thanks! Worked perfectly.

  5. Unixmonkey says:

    Saved me the hassle of firing up another django app, setting the admin password, and copying over the sha1 hash from one database to another.

    Thanks a lot.

  6. Ed W says:

    You are a godsend! That worked and it saved my bacon.
    Well, at least it saved me from having to painfully re-install
    the app. (Installing the app was PAINFUL.)

  7. Gerard says:


    Is this useful or what! I mean am I stupid or what .. ;-)



  8. trailblazer says:

    thanks a lot. I’m new to django. I’ve created site set some silly password and forgot. I didn’t even remember I’ve created something like super user. It was only when I read from second tutorial on django site that I came to know about it.

  9. rorys says:

    This didn’t work for me as described above, but did work if I did the following:

    >>> from django.contrib.auth.models import User
    >>> users = User.objects.all()
    >>> u = users[0]
    >>> u.set_password(‘whatever’)

    Perhaps this is an issue with the newest version of Django? Not sure. but hopefully that will be helpful to someone else.


    • japa says:

      I confirm this worked for me with Pinax (using Django 1.3) while the original did not work. Thanks

  10. Rafa says:

    rorys, thanks for your contribution, it worked for me. thanks bruce too :)

  11. Pascal says:

    Rorys example worked for me. Thank you

    • Hobs says:

      Likewise for me (and apparently Amit). I’m using the latest development Django (as of 2010-08-10), fully updated Ubuntu distribution of Python 2.6 (r265:79063, Apr 16 2010, 13:09:56), and development version of Pinax (0.9…?). Perhaps something to do with Python 2.6 object array dereferencing with brackets?

  12. billschen says:

    thank you very much! it’s helpful!

  13. Elias Hedberg says:

    Using Django 1.1.1 I had to use Amit Chakradeo’s/rorys’ way of doing it, but that worked like a charm. :-)

  14. Elias Hedberg says:

    I was too quick…

    Using the method Amit/rorys described _did_ change the password in django.contrib.auth.models.User but it _did_not_ let me log into the development server :-( . Neither could I log in with a new superuser created according to the instructions in the tutorial.

    I’ll investigate it and report any solution I find.

  15. Elias Hedberg says:

    I still don’t know what caused the problem, but changing the browser helps. In Google Chrome (5.0.342.7 on Mac OS X 10.6.3) I cannot log in when I get to the second part of the Django tutorial and the terminal outputs a fairly long report ending with “error: (32, ‘Broken pipe’)”.

    However, changing to Firefox (3.6.3) let’s me log in. (I was tipped off by this post:

    I still don’t know what the problem is but a work-around is good enough at the moment and maybe it can be helpful to someone else too.

  16. Owen Byrne says:

    The method from the comments worked for me. You might want to remove that semi-colon, since it betrays a background with some less cool language.
    .-= Owen Byrne´s last blog ..Top Digg Unpromoted Stories 2009-12-05 to 2009-12-12 =-.

  17. rcmichelle says:

    you can try to google Password Genius

  18. Diomedes Alakazam says:

    (4+ years later – still this post is found at google and helps the occasional person that forgets the obvious…)

    Anyway, was curious why Amit’s reply worked (while the orignal didn’t).
    So it seems that he important difference is that Amit does

    user = …

    instead of the original post which was working on the full path

    After failing to change the password in that way I just rewrote it as

    user = users[0]

    and that worked perfectly.


  19. Jonathan says:

    I think understand why:
    doesn’t work, rory’s solution does.

    It is because ‘users’ is a queryset, which essentially means that “users[0]” is better thought of as the execution of a function instead of an “object” that is storing information about the user. When users[0] is called, it executes a database query and returns the result. In other words, “users[0].set_password(‘whatever’)” returns the information of the user with the modified password, but this information is *not* saved in users[0], since a queryset can’t actually hold the result of the database query.

  20. Marconius says:

    ~/my/app$ ./ changepassword admin


    Me thinks this is the best way to do it now.

  21. Val says:

    It make sense to change the password via a configuration setting prior to a syncdb specially if you are on the production server. You don’t want to jump into typing python code directly.

    Check django-bootup for more details.

  22. Bill says:

    Why not just do it from the manager?

    ./ changepassword admin

  23. Bruce Kroeze says:

    Posters who are pointing out that you can now do that from a simple “changepassword” command are right! When I wrote this, there was no such command. Now it is much easier.


  1. [...] Howto Reset The Admin Password in Django In [1]: from django.contrib.auth.models import User In [2]: users = User.objects.all() In [3]: users Out[3]: [] In [4]: users[0].set_password(’whatever’); In [5]: users[0].save() (tags: django password recovery login auth commandline python) [...]

  2. [...] Howto Reset The Admin Password in Django | Coder's Eye (tags: django) [...]

Speak Your Mind