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 (1153) [earned 5 cycles]
View Answer
Comments
hotnewtop
timmy_i_chen (1153)

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!

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.

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

darrellhubbard (1)

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

ch1ck3n (1621)

@darrellhubbard bruh that is a genius idea

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 (1621)

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

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.

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

rashidey (1)

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