Getting Started With Django Rest part 3
Adding Database Settings to .env file¶
In your env file, add the following. Ill be using postgresql for my testing database.
Add the following in your settings file
if os.environ.get('ENVIRONMENT') == 'testing':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'URL': os.environ.get('PG_URL'),
'NAME': os.environ.get('PG_NAME'),
'USER': os.environ.get('PG_USER'),
'PASSWORD': os.environ.get('PG_PASSWORD'),
'HOST': os.environ.get('PG_HOST'),
'PORT': os.environ.get('PG_PORT'),
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
Adding static files settings¶
In order to tell django where to store static files, Add the following to the settings.py
file
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
MEDIA_URL = "media/"
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
Adding urls¶
in the urls.py
file under myProject/myProject/urls.py
add the following lines