Create your application project
You will initially create your Django projects and application outside of Bluemix. That way you will have more control over the project structure. You can start from either the flask boilerplate or the Python runtime.
- Create the project named
> django-admin startproject projwatsonYour project skeleton should now have been created, which you can run and see the “Hello Django” page and see the administration features.
- Change the directory to projwatson and start the application:
projwatson> python manage.py runserver
You should see that the server is running at http://127.0.0.1:8000/.
On the https://localhost:8000/admin page, you’ll see a login prompt for to the administration page, but you will not be able to log in because you did not yet created an administrator ID.
On the console, notice a message that says that you have unapplied migrations.
The migrations refer to your database and models. At this point, the application is using the default Django embedded sqllite3 database.
If you want to remove this message, you must run the migrate command as specified in the message. You will need to repeat this every time you make a database or model change. When you do make model changes, the migration is a two-step process, and you should always perform both steps together. On the initial run, the first step will show “No changes detected,” but it’s a good habit to get into every time you deploy your application changes.
These are the actions that your application deployment must take every time there is a database schema change, including the initial deployment.
- Use Control <C> to interrupt the application and then generate the migration SQL:
projwatson> python manage.py makemigrations
- Start the migrations:projwatson> python manage.py migrate
- Create your administrator user ID:
projwatson > python manage.py createsuperusercreatesuperuser command requires user interaction, it will not work when you deploy to Bluemix, so here’s an alternative way through a Python shell.
- Start the shell with this command:
rojwatson > python manage.py shell
- In the shell, create the superuser by passing in the user name, password, and email address:
>>> from django.contrib.auth.models import User
>>> User.objects.create_superuser(username='myadminid', password='mypassword', email='[email protected]')
- Note any exception that’s thrown. After the shell is created, if you run the
createcommand again, you will see an IntegrityError exception. When you deploy in Bluemix, your application launch code will need to trap this exception; otherwise, the application won’t start.
- Exit the shell:
- Restart the server and log in to the administrator page at https://localhost:8000/admin.