View on GitHub

Code Fellows reading notes

A repository for organizing notes from my learning.

API Deployment

Django Settings Best Practices

Source: djangostars - Configuring DJango Settings

When considering the management of Django settings, there are some key issues to consider:

Let’s examine popular approaches to handling settings:

settings_local.py

The oldest method, settings_local.py is used to extend environment-specific settings.

Pros:

Cons:

Separate settings file for each environment

This involves creating a settings package, with various environment settings in their own modules.

When taking this approach, a settings will need to specified when running a project:

python manage.py runserver --settings=settings.local

Pros:

Cons:

Environment variables

Environment variables solve the sensitive data problem, but can be clunky to work with and require manual typing.

They can be accessed via os.environ.

But wait, does Django have a thing?

Yes.

django-environ

django-envron is a merge of the following tools:

Here’s an example of settings using django-environ:

#from djangostars:

import environ


root = environ.Path(__file__) - 3  # get root of the project
env = environ.Env()
environ.Env.read_env()  # reading .env file

SITE_ROOT = root()

DEBUG = env.bool('DEBUG', default=False)
TEMPLATE_DEBUG = DEBUG

DATABASES = {'default': env.db('DATABASE_URL')}

public_root = root.path('public/')
MEDIA_ROOT = public_root('media')
MEDIA_URL = env.str('MEDIA_URL', default='media/')
STATIC_ROOT = public_root('static')
STATIC_URL = env.str('STATIC_URL', default='static/')

SECRET_KEY = env.str('SECRET_KEY')

CACHES = {'default': env.cache('REDIS_CACHE_URL')}

And the associated .env file:

Also from djagnostars:

DEBUG=True
DATABASE_URL=postgres://user:password@db.example.com:5432/production_db?sslmode=require
REDIS_CACHE_URL=redis://user:password@cache.example.com:6379/1
SECRET_KEY=Some-Autogenerated-Secret-Key

Best Practices

SSH Tutorial

Source: Hostinger Tutorials - How Does SSH Work

What is SSH

SSH (Secure Shell) is a remote administration protocol that allows users to control and modify remote servers over the internet.

How to use

On Linux and Mac, using SSH is simple. Go to the terminal, and use the following command:

$ ssh {user}@{host}

This tells the system at {host} that you want to login as {user}. You will prompted for a password. If submitted password is correct you will be greeted by a remote terminal window. That’s it!

SSH sessions are securely encrypted, using a combination of symmetric encryption, asymmetric encryption, and hashing.

Additional Resources