Skip to content

Commit

Permalink
feat: Add django-debug-toolbar and silk middleware for development en…
Browse files Browse the repository at this point in the history
…vironment, update settings and URLs
  • Loading branch information
AhmedNassar7 committed Dec 25, 2024
1 parent 8a4d630 commit 858cad3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
32 changes: 20 additions & 12 deletions egypt_metro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,26 @@
]
CORS_ALLOW_CREDENTIALS = True # Allow credentials

if ENVIRONMENT == "dev":
INSTALLED_APPS += ["silk"]
MIDDLEWARE += ["silk.middleware.SilkyMiddleware"]

SILKY_PYTHON_PROFILER = True # Enables Python code profiling
SILKY_MAX_REQUESTS = 1000 # Limit the number of requests to profile
SILKY_RECORD_SQL = True # Records SQL queries
SILKY_AUTHENTICATION = True # Protect Silk interface with authentication
# if ENVIRONMENT == "dev":
# INSTALLED_APPS += [
# "silk",
# "debug_toolbar",
# ]
# MIDDLEWARE += [
# "silk.middleware.SilkyMiddleware",
# "debug_toolbar.middleware.DebugToolbarMiddleware",
# ]

# INTERNAL_IPS = [
# "127.0.0.1", # Localhost
# "localhost", # Localhost
# "0.0.0.0", # Docker/Container or VM access
# ]

# SILKY_PYTHON_PROFILER = True # Enables Python code profiling
# SILKY_MAX_REQUESTS = 1000 # Limit the number of requests to profile
# SILKY_RECORD_SQL = True # Records SQL queries
# SILKY_AUTHENTICATION = True # Protect Silk interface with authentication

TEMPLATES = [
{
Expand Down Expand Up @@ -325,10 +337,6 @@
SESSION_EXPIRE_AT_BROWSER_CLOSE = ENVIRONMENT == "dev" # True for development, False for production
SESSION_SAVE_EVERY_REQUEST = True # Save session data on every request

INTERNAL_IPS = [
"127.0.0.1", # Localhost
]

HANDLER404 = "egypt_metro.views.custom_404" # Custom 404 handler
HANDLER500 = "egypt_metro.views.custom_500" # Custom 500 handler

Expand Down
9 changes: 5 additions & 4 deletions egypt_metro/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,19 @@
), # Swagger UI

path("redoc/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"), # ReDoc

# Silk Profiling
path("silk/", include("silk.urls", namespace="silk")) if settings.ENVIRONMENT == "dev" else None,
]

# Debug the URL loading process
# logger.debug('URL patterns: %s', [path.pattern for path in urlpatterns])

# Debug Toolbar (only for development)
# if settings.DEBUG:
# import debug_toolbar # type: ignore

# urlpatterns += [
# path("__debug__/", include("debug_toolbar.urls")), # Debug toolbar
# path('__debug__/', include(debug_toolbar.urls)), # Debug toolbar
# static(settings.STATIC_URL, document_root=settings.STATIC_ROOT),
# path("silk/", include("silk.urls", namespace="silk"))
# ]

# Static and media files (if DEBUG is enabled)
Expand Down
17 changes: 16 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ django-db-geventpool = "^4.0.7"
django-silk = "^5.3.2"
django-constance = "^4.1.3"
simplejwt = "^2.0.1"
django-debug-toolbar = "^4.4.6"
[tool.poetry.dev-dependencies]
pytest = "^6.2.4" # Pytest for unit testing
pytest-asyncio = "^0.15.1" # Pytest plugin for asyncio tests
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ django-allauth==65.3.0 ; python_version >= "3.10" and python_version < "4.0"
django-constance==4.1.3 ; python_version >= "3.10" and python_version < "4.0"
django-cors-headers==4.6.0 ; python_version >= "3.10" and python_version < "4.0"
django-db-geventpool==4.0.7 ; python_version >= "3.10" and python_version < "4.0"
django-debug-toolbar==4.4.6 ; python_version >= "3.10" and python_version < "4.0"
django-environ==0.11.2 ; python_version >= "3.10" and python_version < "4"
django-redis==5.4.0 ; python_version >= "3.10" and python_version < "4.0"
django-silk==5.3.2 ; python_version >= "3.10" and python_version < "4.0"
Expand Down

0 comments on commit 858cad3

Please sign in to comment.