Skip to content

Strip whitespace from comma-separated environment variables in Django settings#7

Draft
Copilot wants to merge 3 commits intosetupfrom
copilot/sub-pr-6
Draft

Strip whitespace from comma-separated environment variables in Django settings#7
Copilot wants to merge 3 commits intosetupfrom
copilot/sub-pr-6

Conversation

Copy link

Copilot AI commented Feb 17, 2026

ALLOWED_HOSTS was using .split(',') without trimming whitespace, causing Django to reject entries like ' localhost' when .env files contain spaces around commas.

Changes

  • Updated ALLOWED_HOSTS to strip whitespace and filter empty strings, matching the existing CORS_ALLOWED_ORIGINS pattern
  • Uses generator expression to avoid redundant strip() calls
# Before
ALLOWED_HOSTS = os.getenv("DJANGO_ALLOWED_HOSTS", "localhost,127.0.0.1").split(",")

# After
ALLOWED_HOSTS = [
    host
    for host in (
        h.strip() for h in os.getenv("DJANGO_ALLOWED_HOSTS", "localhost,127.0.0.1").split(",")
    )
    if host
]

Handles common .env formatting: DJANGO_ALLOWED_HOSTS="localhost, 127.0.0.1, 0.0.0.0" now parses correctly.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 17, 2026 01:00
Co-authored-by: Davictory2003 <68972845+Davictory2003@users.noreply.github.com>
Co-authored-by: Davictory2003 <68972845+Davictory2003@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on initial project set-up PR Strip whitespace from comma-separated environment variables in Django settings Feb 17, 2026
Copilot AI requested a review from Davictory2003 February 17, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants