Skip to content

Commit 7aacd17

Browse files
committed
This commit updates the loading of environment variables, adds dotenv functionality, removes an unused import in Python code, and updates dependencies versions.
Commit Description: - Added dotenv functionality to load environment variables - Improved error handling for missing .env file - Removed unused import statement for apidemo.urls in Python code - Updated versions of various dependencies: - annotated-types - Django - django-ninja - orjson - packaging - pydantic - pydantic_core - python-dotenv
1 parent 47a88c7 commit 7aacd17

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

apidemo/apidemo/settings.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@
1212
import os
1313
from pathlib import Path
1414

15+
from dotenv import find_dotenv, load_dotenv
16+
17+
# The code `env_file = find_dotenv(filename=".env", raise_error_if_not_found=True)` is used to find
18+
# the `.env` file in the project directory. The `find_dotenv` function searches for the `.env` file
19+
# and returns its path. If the file is not found, it raises an error.
20+
env_file = find_dotenv(filename=".env", raise_error_if_not_found=True)
21+
22+
# if find_dotenv returns True i.e .env file is found, simply ignore
23+
# dotenv_path argument in load_dotenv
24+
load_environ = load_dotenv(encoding="utf-8", override=True,interpolate=True)
25+
26+
if not load_environ:
27+
raise "Environment Variables not loaded!"
28+
1529
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1630
BASE_DIR = Path(__file__).resolve().parent.parent
1731

@@ -23,7 +37,7 @@
2337
SECRET_KEY = os.getenv("DJANGO_SECRET", None)
2438

2539
# SECURITY WARNING: don't run with debug turned on in production!
26-
DEBUG = True
40+
DEBUG = os.getenv("DEBUG", False)
2741

2842
ALLOWED_HOSTS = []
2943

apidemo/test_app/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from django.shortcuts import get_object_or_404
66
from ninja import NinjaAPI, Schema
77

8-
# from apidemo.urls import api_v1, api_v2
98
from test_app.models import Department, Employee
109

1110
api_v1 = NinjaAPI()

requirement.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
annotated-types==0.5.0
1+
annotated-types==0.6.0
22
asgiref==3.7.2
33
colorama==0.4.6
4-
Django==4.2.5
5-
django-ninja==0.22.2
6-
orjson==3.9.7
7-
packaging==23.1
4+
Django==4.2.6
5+
django-ninja==1.0b2
6+
orjson==3.9.10
7+
packaging==23.2
88
pip-review==1.3.0
99
PLTable==1.0.2
10-
pydantic== 1.10.12
11-
pydantic_core==2.10.0
10+
pydantic==2.4.2
11+
pydantic_core==2.10.1
12+
python-dotenv==1.0.0
1213
sqlparse==0.4.4
1314
typing_extensions==4.8.0
1415
tzdata==2023.3

0 commit comments

Comments
 (0)