Editing
Creating a Django Admin Account on Elastic Beanstalk
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
[[Category:AWS]] [[Category:Django]] [[Category:Web Development]] Create a custom Django command. Custom Django commands are placed in a package named `management.commands` in an app separate from the main app, e.g. `project_root/not_main_app/management/commands/my_custom_command.py`. Django can locate the commands automatically when running `manage.py` when they follow this convention. <syntaxhighlight lang="python"> # not_main_app/management/commands/create_su.py import os from django.core.management.base import BaseCommand from com.cygora.apps.users.models.User import User class Command(BaseCommand): def handle(self, *args, **options): username = os.environ['SU_USERNAME'] if not User.objects.filter(username=username).exists(): User.objects.create_superuser(username, os.environ['SU_USERNAME'], os.environ['SU_PASSWORD']) </syntaxhighlight> Note that it's essential to place `__init__.py` files in each of the directories all the way down to the `commands` directory. I created a package solely for the purpose of hosting this management command named `eb_deploy`. Add a containers command to a `.ebextensions` `.config` file. ''(This should come after migration commands.)'': <syntaxhighlight lang="yaml"> container_commands: 02_create_superuser_for_django_admin: command: "python manage.py create_su" leader_only: true </syntaxhighlight> == Notes == * [http://stackoverflow.com/a/22639516/1399562 Create a login and pass for Django Admin on AWS] - Stack Overflow, Mar 2014
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information