Ask coding questions

← Back to all posts
Django - How to create a superuser?
AntonHutchinson (6)

Trying to get a Django app going and it comes with the admin / user system in place and I can navigate to /admin. But I can't create a super user in the terminal, as it simply has the server running.

Answered by timmy_i_chen (1165) [earned 5 cycles]
View Answer
timmy_i_chen (1165)

Here's a template you can use to run django commands:

We'll be improving the django experience very soon. Sorry about this!

AntonHutchinson (6)

I realised I could do this by creating a new migration file.

Link to the content I put into the migration file to create a superuser.

darrellhubbard (1)

Great! I figured out how to do so. What I did is went to next I import the module os. Then create a function call createSuperUser(request): I then create a variable called admin and set it equal to os.system("python createsuperuser"). then after that return admin. Finally restart the django site, then it will prompt you in the terminal. Man I am so brillant. lol

darrellhubbard (1)

@ch1ck3n wow about a year ago I posted this! did not even think that someone would have come across this idea. amazing! thank you! your comment is encouragement to continue to learn and expand.

ch1ck3n (1738)

@darrellhubbard I lurk around the second page of the google search every once in a while

PraveenVishwaka (0)

Step 1: startproject
Step 2: startapp and add it to
Step 3: run these commands on console , python makemigrations and python migrate
Step 4: then run this cmd , python createsuperuser, put name(remember it will be used to login), password(remember) , email, etc.
Step 5: go to admin page <your url>/admin
Step 6: login with username and password you created

rashidey (1)

please i cant run startapp and superuser

AntonHutchinson (6)

@rashidey Create a new migration in which you can define and save a superuser. You then need to run the migration in order to create the user. You will then be able to log in as a superuser.

See my prior comment.

AntonHutchinson (6)

Hi @B0TProject

Check in my repl file structure within migrations section.

Once you create this file you can run migrations in the console and your superuser should be created. Then you can log into the /admin section.

rashidey (1)

how i can add to run command template out of main folder @rashidey