Skip to content

Commit

Permalink
Create Django Superuser
Browse files Browse the repository at this point in the history
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
jpetazzo committed Sep 1, 2011
1 parent 00b9155 commit 95c5cf1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mkadmin.py
Original file line number Diff line number Diff line change
@@ -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
u.save()
1 change: 1 addition & 0 deletions postinstall
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
python hellodjango/manage.py syncdb --noinput
python mkadmin.py

0 comments on commit 95c5cf1

Please sign in to comment.