24.5.2 The createuser and createsuperuser Commands

The createuser and createsuperuser commands are much more involved than the createtag command, but the principle is the same. In /user/management/commands/ we create a file called createuser.py for the createuser command and a file called createsuperuser.py for the createsuperuser command. In both files, we declare a Command class, which inherits from BaseCommand. Our goal is to define the add_arguments() and handle() methods.

We take this a step further and imitate the createsuperuser.py command supplied by auth. The command has two ways of working: interactively and non-interactively. If you checkout a commit in the git repo from before Chapter 22, you’ll be able to see this for yourself. To ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.