Skip to content

Instantly share code, notes, and snippets.

@bachkukkik
Last active August 30, 2020 08:50
Show Gist options
  • Save bachkukkik/50915c630825f929987e2fdbccf87ccf to your computer and use it in GitHub Desktop.
Save bachkukkik/50915c630825f929987e2fdbccf87ccf to your computer and use it in GitHub Desktop.

Root of the Django project is where manage.py resides

Prerequisites

  • $ mkdir basic_django
  • $ cd basic_django
  • $ virtualenv assume user already !pip install --user virtualenv
  • $ virtualenv -p python3 .
  • $ source bin/activate
  • $ pip install django
  • $ deactivate if you don't need virtualenv

Start Django

  • $ django-admin to see list of django commands
  • $ mkdir ./src && cd ./src
  • $ django-admin startproject <your project name> .
  • $ python manage.py runserver

settings.py

  • BASE_DIR = project location
  • ALLOWED_HOSTS = list of urls that can access django project
  • INSTALLED_APPS = installed components for particular django project
  • MIDDLEWARE = tell us how requests/security are handled
  • ROOT_URLCONF = tell us how urls are routing
  • TEMPLATES = tell us how html pages should be rendered
  • WSGI_APPLICATION = tell us how server works
  • DATABASES = databases mapping
  • AUTH_PASSWORD_VALIDATORS = password's standards
  • STATIS_URL = tell us where do we store static files
  • $ python manage.py migrate to Sync changes in settings

APPs

  • django has built-in apps. We also can install third-party apps.
  • $ python manage.py migrate to Sync changes in settings including auth, admin apps
  • $ python manage.py createsuperuser create the ultimate user
  • $ python manage.py startapp <your appp name> create apps
  • you may edit your newly created apps, you may also need to update apps in INSTALLED_APPS
  • $ python manage.py makemigrations Update what are we migrating
  • $ python manage.py migrate actually sync settings
  • Also register your models in the relative admin.py admin.site.register(Product)

Shell

  • $python manage.py shell work with django project in (kind of) python shell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment