Skip to content

Instantly share code, notes, and snippets.

@johndhancock
Last active July 14, 2017 18:47
Show Gist options
  • Save johndhancock/cb4923143603459c40150dfa298e0968 to your computer and use it in GitHub Desktop.
Save johndhancock/cb4923143603459c40150dfa298e0968 to your computer and use it in GitHub Desktop.

Starting a django project from the command line

django-admin startproject <project name>


Starting up the django server

From within the app root directory:

python manage.py runserver 0.0.0.0:8000


Running python migrations

python manage.py migrate <appname is optional>


Creating an app

python manage.py startapp <appname>


Making migrations

After a new model is created, we need to make migrations for our app.

python manage.py makemigrations <appname is optional>


Opening a shell with django configuration

python manage.py shell


Saving an in-memory instance of a model to a database

Within python shell <Model>.save

Example:

from <appname>.models import <Model>
c = Course()
c.title = "Python Basics"
c.save()

Creating and saving a model in one go

Within python shell <Model>.create

Example:

Course.objects.create(title="Object-Oriented Python")

Creating super users

python manage.py createsuperuser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment