Skillversitas

Installation and Project Setup

The setup is the venv plus the pip plus the startproject: the python3 -m venv .venv the isolated (the pip the project the no the system), the pip install django the 5.x (the LTS the 4.2 the 3 year), and the django-admin startproject notes . the 4 file (the manage.py, the settings, the urls, the wsgi). The settings.py is the config (the SECRET_KEY, the DEBUG, the ALLOWED_HOSTS, the DATABASES), and the env is the secret (the 12factor, the .env the git the no). This chapter covers the venv (the create, the activate), the pip (the 5.x, the pin), the startproject (the 4 file, the settings), and the Notes app the startapp the 2 file.

The venv and the pip

# the VENV (the isolated, the no system):
python3 -m venv .venv
source .venv/bin/activate   # the zsh's
                        #   the Windows:
                        #   .venv\Scripts\activate
pip install --upgrade pip
pip install django==5.1.4   # the 5.x (the
                            #   4.2 the LTS)
python -c "import django; print(
    django.get_version())"
#   the 5.1.4

# the PIN (the requirements.txt, the CI's):
pip freeze > requirements.txt
#   the Django==5.1.4
#   the asgiref==3.x
#   the sqlparse==0.5.x
pip install -r requirements.txt
#   the reproducible (the no the
#     the version's the float)

The venv is the isolated: the python3 -m venv .venv the create (the 3 dir the bin the lib the pyvenv.cfg), and the source .venv/bin/activate the activate (the PROMPT the (.venv) the shell, the pip the venv the no the system) - the deactivate is the exit (the venv the no the touch). The pip install django==5.1.4 is the pin (the 5.x the modern, the 4.2 the LTS the 3 year the support), and the requirements.txt is the reproducible (the pip freeze the lock, the CI the install the same the version) - the .gitignore is the .venv plus the .env (the venv the binary the no the commit, the secret the env the no the repo). The startproject is the next section: the 4 file the settings the no the template.

The startproject and the settings

# the STARTPROJECT (the 4 file, the . the
#   the root):
django-admin startproject notes .
#   the notes/          (the package)
#     the __init__.py
#     the settings.py   (the config)
#     the urls.py       (the route)
#     the wsgi.py       (the server)
#   the manage.py       (the command)

# the SETTINGS (the config, the 4 change):
#   the 1: the SECRET_KEY (the 50 char,
#     the env's, the no the commit)
SECRET_KEY = os.environ.get(
    "DJANGO_SECRET_KEY")
#   the 2: the DEBUG (the False the
#     the production, the 12factor)
DEBUG = os.environ.get(
    "DJANGO_DEBUG") == "1"
#   the 3: the ALLOWED_HOSTS (the 12factor,
#     the no the empty)
ALLOWED_HOSTS = os.environ.get(
    "DJANGO_ALLOWED_HOSTS",
    "localhost,127.0.0.1").split(",")
#   the 4: the DATABASES (the SQLite the
#     the dev, the Postgres the prod)
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}

The django-admin startproject notes . is the 4 file: the manage.py (the command the migrate the runserver the shell), the notes/settings.py (the config, the 4 change the production), the notes/urls.py (the route the path), and the notes/wsgi.py (the server the gunicorn the WSGI). The settings.py is the 4 change: the SECRET_KEY (the 50 char, the env the no the commit, the sign the session the token), the DEBUG (the False the production the traceback the hide, the env the 12factor), the ALLOWED_HOSTS (the empty the 400 the production), and the DATABASES (the SQLite the dev the no the config, the Postgres the prod the psycopg) - the INSTALLED_APPS is the 8 default (the admin, the auth, the sessions, the messages, the staticfiles) - the Notes app is the startapp the next chapter: the 2 file the no the template.

The startapp: The Notes app

# the STARTAPP (the 2 file, the notes app):
python manage.py startapp notes_app
#   the notes_app/
#     the __init__.py
#     the models.py     (the empty)
#     the views.py      (the empty)
#     the admin.py      (the empty)
#     the urls.py       (the no, the
#       the create)
#     the apps.py       (the config)
#     the migrations/__init__.py
#     the tests.py      (the empty)

# the REGIST (the settings, the 1 line):
#   the INSTALLED_APPS += [
#       "notes_app",   #   the app's
#     ]
#   the the app's the no the INSTALLED_APPS
#     the the no the register (the admin's
#     the no, the migration's the no)

# the RUN (the server, the 127.0.0.1:8000):
python manage.py runserver
#   the 1: the WSGI (the no the gunicorn)
#   the 2: the auto-reload (the file the
#     the change the 1s)
#   the 3: the 0.0.0.0:8000 the network
#     (the no the localhost only)

The python manage.py startapp notes_app is the 7 file: the models.py (the empty, the Note the next), the views.py (the empty, the list the next), the admin.py (the empty, the register the next), the apps.py (the config the NotesAppConfig), the migrations/ (the empty, the makemigrations the next), and the tests.py (the empty, the Test the next) - the urls.py is the create (the app the route, the project the include). The INSTALLED_APPS is the register (the "notes_app" the 1 line, the no the admin the no the migration the no the signal), and the runserver is the 127.0.0.1:8000 (the auto-reload the file the change, the 0.0.0.0 the network) - the 12factor is the env (the SECRET_KEY the export, the DEBUG the 0), and the rule is the one: the venv the isolated, the pip the pin the 5.x, the startproject the 4 file, the settings the 4 change the env, and the startapp the 7 file the INSTALLED_APPS the register - the next chapter's MVT is the 3 layer the request the flow.

The Working Rules

  • The venv is the isolated, the activate the shell. The python3 -m venv .venv the create, the source .venv/bin/activate the (.venv) the prompt, and the deactivate the exit - the .gitignore the .venv plus the .env (the binary the no the commit, the secret the no the repo).
  • The pip is the pin, the 5.x the LTS the 4.2. The pip install django==5.1.4 the pin (the 5.x the modern), and the requirements.txt the reproducible (the pip freeze the lock, the CI the same) - the upgrade the pip first, the uninstall the venv the no the system.
  • The startproject is the 4, the settings the 4 change. The manage.py the command, the settings.py the config (the SECRET_KEY the env, the DEBUG the 12factor, the ALLOWED_HOSTS the no the empty, the DATABASES the SQLite the dev), and the wsgi.py the gunicorn - the startapp the 7 file the next.
  • The INSTALLED_APPS is the register, the 1 line. The "notes_app" the 1 line (the no the admin, the migration, the signal the no), and the runserver the 127.0.0.1:8000 (the auto-reload, the 0.0.0.0 the network) - the 12factor the env the SECRET_KEY the export the DEBUG the 0.

Summary

The setup is the 3: the venv (the python3 -m venv .venv, the source .venv/bin/activate, the .gitignore the .venv), the pip (the pip install django==5.1.4 the 5.x, the 4.2 the LTS, the requirements.txt the pip freeze the reproducible), and the startproject (the django-admin startproject notes . the 4 file, the settings.py the 4 change: the SECRET_KEY the env, the DEBUG the 12factor, the ALLOWED_HOSTS the no the empty, the DATABASES the SQLite). The startapp notes_app is the 7 file (the models, the views, the admin, the apps, the migrations, the tests), and the INSTALLED_APPS is the register the 1 line (the "notes_app") - the runserver the 127.0.0.1:8000 the auto-reload. The next chapter's MVT is the 3 layer: the Model the data, the View the logic, the Template the HTML, and the request the flow the URL the View the QuerySet the DB the Template the response.