Alecg_O
Alecg_O

Reputation: 1039

django manage.py createsuperuser not accepting username

I'm learning django and working through this tutorial on the djangoproject website. It's gone fine so far but I'm running into issues with the "python manage.py createsuperuser" command.

Username (leave blank to use 'alecgo'):

When I run the command, the prompt above displays as expected, but when I enter a username, it gets kicked back with the error below.

Username (leave blank to use 'alecgo'): admin
Error: Enter a valid username.
Username (leave blank to use 'alecgo'): 

This happens no matter what I input as a username (or if I leave it blank), and it prevents me from moving forward with the admin user.

Thanks in advance for any help.

Update/Edit: I didn't think to include this but it might be relevant that I have django installed and am running everything inside a virtual environment, not on my main Python library.

Upvotes: 4

Views: 2626

Answers (1)

David Sanders
David Sanders

Reputation: 4139

Not sure why that would happen, but you can open up the django console using python manage.py shell and then do:

from django.contrib.auth.models import User
User.objects.create_superuser(u'username', u'email', u'password')

That might work. You could perhaps also put the above code in a python file (let's call it myfile.py) with an explicit encoding:

# -*- coding: utf-8 -*-
from django.contrib.auth.models import User

if __name__ == '__main__':
    User.objects.create_superuser(u'username', u'email', u'password')

...and then execute the file from the command line like so: DJANGO_SETTINGS_MODULE=<path to your settings file> python -m myfile. You could also just import your file from the django console:

from myfile import *

Note that, from either the command-line or the django console, you would enter myfile and not myfile.py. Also, always ensure that your string literals are prefixed with u so python interprets them as code point strings.

Upvotes: 4

Related Questions