Skip to content
← Back to Community
Django - How to create a superuser?
Profile icon
AntonHutchinson

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 [earned 5 cycles]
View Answer
Voters
Profile icon
MuskanAi
Profile icon
goncalog
Profile icon
solly_ucko
Profile icon
B0TProject
Comments
hotnewtop
Profile icon
timmy_i_chen

Here's a template you can use to run django commands: https://repl.it/@masfrost/Django-Boilerplate

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

Profile icon
AntonHutchinson

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.

https://gist.github.com/inirudebwoy/7eb2d74ea950c38559e5

Profile icon
darrellhubbard

Great! I figured out how to do so. What I did is went to VIEWS.py. 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 manage.py 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

Profile icon
ch1ck3n

@darrellhubbard bruh that is a genius idea

Profile icon
darrellhubbard

@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.

Profile icon
ch1ck3n

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

Profile icon
PraveenVishwaka

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

Profile icon
rashidey

please i cant run startapp and superuser

Profile icon
AntonHutchinson

@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.

Profile icon
B0TProject
Profile icon
AntonHutchinson

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.

https://repl.it/@AntonHutchinson/FitnessApp

Profile icon
rashidey

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