Add subdomains of localhost to ALLOWED_HOSTS in DEBUG mode

314 views
Skip to first unread message

Gordon

unread,
Nov 21, 2019, 4:40:40 PM11/21/19
to Django developers (Contributions to Django itself)
Good afternoon,

It seems pretty straightforward to me as a win with no downsides.  Chrome resolves subdomains of localhost as localhost.  I did a little searching (but forgot to keep the sources) and discovered that this behavior was intentional and spec compliant.  This is extremely handy for local development since it allows one to test subdomains without fooling with network DNS or modifying host files.

I opened ticket https://code.djangoproject.com/ticket/31010 and was asked to canvas for opinions.

I think that updating the handling of ALLOWED_HOSTS in HttpRequest.get_host()from:

        # Allow variants of localhost if ALLOWED_HOSTS is empty and DEBUG=True.
        allowed_hosts = settings.ALLOWED_HOSTS
        if settings.DEBUG and not allowed_hosts:
            allowed_hosts = ['localhost', '127.0.0.1', '[::1]']

to

        # Allow variants of localhost if ALLOWED_HOSTS is empty and DEBUG=True.
        allowed_hosts = settings.ALLOWED_HOSTS
        if settings.DEBUG and not allowed_hosts:
            allowed_hosts = ['.localhost', '127.0.0.1', '[::1]']

would be safe and support this pattern without requiring any changes to settings files which is quite nice for new projects.  Please let me know what you think =)

Thanks,
Gordon



Adam Johnson

unread,
Nov 21, 2019, 4:49:34 PM11/21/19
to django-d...@googlegroups.com
I’m all in favour of making development easier. Would be in favour of this if I could see a source :) Also can you check the behaviour in more browsers than Chrom(e|ium)? :)

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/b9e276f0-76f1-4a9c-be22-cb7286c20ec5%40googlegroups.com.
--
Adam

gordon

unread,
Nov 21, 2019, 4:58:37 PM11/21/19
to django-d...@googlegroups.com
Spec:
It didn't seem to work on IE edge.  At the rate of browser updates I expect all browsers to support this by 2090.  But it does make development on Chrome nice now =)

You received this message because you are subscribed to a topic in the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-developers/xcoAF9Gm_dI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM0ufpyu50t_tbACPrEwJ94LYTWGyfywGzooA7%3D3pVnXBw%40mail.gmail.com.

Harro

unread,
Nov 22, 2019, 12:36:28 AM11/22/19
to Django developers (Contributions to Django itself)
I assume that just localhost still works with the above change?

If so then the fact that IE edge does not support it is no reason to not change it because nothing changes with the current usage.

אורי

unread,
Nov 22, 2019, 1:31:52 AM11/22/19
to Django developers (Contributions to Django itself)

Adam Johnson

unread,
Nov 22, 2019, 3:28:29 AM11/22/19
to django-d...@googlegroups.com
Spec seems clear enough. Seems like it’s still an open bug in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1433933

Can you reopen the ticket, add the spec link to the description, and open a PR? Thanks!

--
Adam
Reply all
Reply to author
Forward
0 new messages