Django 4.1 addtional configs

setting.py

if os.environ.get('DJANGO_CSRF_TRUSTED_ORIGINS'):
    CSRF_TRUSTED_ORIGINS = os.environ.get('DJANGO_CSRF_TRUSTED_ORIGINS').split(' ')
else:
    CSRF_TRUSTED_ORIGINS = []

if os.environ.get('DJANGO_ACCOUNT_DEFAULT_HTTP_PROTOCOL'):
    ACCOUNT_DEFAULT_HTTP_PROTOCOL = os.environ.get('DJANGO_ACCOUNT_DEFAULT_HTTP_PROTOCOL')
else:
    ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'http'

.env.prod

DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 3.39.199.34 nalcoding.net www.nalcoding.net [::1]
DJANGO_CSRF_TRUSTED_ORIGINS=https://nalcoding.net https://www.nalcoding.net [::1]
DJANGO_ACCOUNT_DEFAULT_HTTP_PROTOCOL=https

nginx.conf

server {
    listen 443 ssl; #ssl 빼 먹으면 안됨
    server_name nalcoding.net;

    location / {
        proxy_pass http://do_it_django;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }

    location /static/ {
        alias /usr/src/app/_static/;
    }

    location /media/ {
        alias /usr/src/app/_media/;
    }
    client_max_body_size 100m;
    ssl_certificate /etc/letsencrypt/live/nalcoding.net/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/nalcoding.net/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

Communicate github repository

Create Github token

User profile -> setting -> developer setting -> Personal access token -> classic -> generate (‘repo’, ‘read:org’, ‘workflow’) -> copy crediential token

Install github cli

(aws lightsail – ubuntu) ssh connect

link : https://github.com/cli/cli/blob/trunk/docs/install_linux.md

curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y

Setup credential info

https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git

ubuntu@atoz:~$ gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Paste an authentication token
Tip: you can generate a Personal Access Token here https://github.com/settings/tokens
The minimum required scopes are 'repo', 'read:org', 'workflow'.
? Paste your authentication token: ****************************************
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as {github name}
ubuntu@atoz:~$

git clone

ubuntu@atoz:~/github$ git clone https://github.com/{github username}/{project name}.git

Cloning into 'do_it_django_a_to_z'...
remote: Enumerating objects: 622, done.
remote: Counting objects: 100% (622/622), done.
remote: Compressing objects: 100% (418/418), done.
remote: Total 622 (delta 298), reused 467 (delta 146), pack-reused 0
Receiving objects: 100% (622/622), 2.43 MiB | 16.49 MiB/s, done.
Resolving deltas: 100% (298/298), done.
ubuntu@atoz:~/github$ ls
do_it_django_a_to_z
ubuntu@atoz:~/github$

docker-compose exec web Superuser creation skipped due to not running in a TTY.

Error Message

docker-compose exec web python manage.py createsuperuser
Superuser creation skipped due to not running in a TTY. You can run manage.py createsuperuser in your project to create one manually

Solution #1

winpty docker-compose exec web python manage.py createsuperuser

Solution #2

docker exec -it ‘container name’ /bin/bash

(inside container)python manage.py createsuperuser