Browse files

Create Django Superuser

Since the ``syncdb`` command was run non-interactively, it did not
prompt us to create a superuser, and therefore, we don't have a
user to login.

To create an admin user automatically, we will write a simple Python
script that will use Django's environment, load the authentication
models, create a ``User`` object, set a password, and give him
superuser privileges.

The user login will be ``admin``, and its password will be ``password``.
Note that if the user already exists, it won't be touched. However,
if it does not exist, it will be re-created. If you don't like this
``admin`` user, you should not delete it (it would be re-added each
time you push your code) but just remove its privileges and reset its
password, for instance.


At this point, if we push the code, we will be able to login, but
we still lack the CSS that will make the admin site look nicer.
  • Loading branch information...
1 parent 00b9155 commit 95c5cf1123e906658534d5613716250b8865f728 @jpetazzo committed Sep 1, 2011
Showing with 10 additions and 0 deletions.
  1. +9 −0
  2. +1 −0 postinstall
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+from wsgi import *
+from django.contrib.auth.models import User
+u, created = User.objects.get_or_create(username='admin')
+if created:
+ u.set_password('password')
+ u.is_superuser = True
+ u.is_staff = True
@@ -1,2 +1,3 @@
python hellodjango/ syncdb --noinput

0 comments on commit 95c5cf1

Please sign in to comment.