How to create a Django superuser if it doesn't exist non-interactively?
<p>I want to automate creation of Django users via a Bash script. I found this snippet which almost suits my needs:   </p>

<pre><code>echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', 'pass')" |\
    python manage.py shell
</code></pre>

<p>How can I modify it so that it's a nop if the user already exists?</p>

<p>you can use <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#get-or-create" rel="nofollow">get_or_create()</a>. If it exists it will do nothing, else it will create one.</p>

<p>You'd have to set the <code>is_staff</code> and <code>is_superuser</code> to <code>True</code> manually</p>

python django django-users