How to add custom trusted_hosts when working with django+nginx+proxy #2917
-
Hi, I would like to implement interactive debugger on my django app. I configured a local domain where nginx has a proxy to my django container. Let's says
I saw that werkzeug test if my domain is on the trusted_hosts but the listed datas are just local ips: werkzeug/src/werkzeug/debug/__init__.py Line 303 in 62e3ea4 My question is how to add my local domain to the trusted_hosts. I saw some exemple for flasks but not for django... Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Most operating systems are now pre-configured to treat Otherwise, the debugger is implemented as WSGI middleware. I'm not entirely sure how to add WSGI middleware to Django (as opposed to Django middelware), but it's definitely possible. app = django.get_wsgi_app() # something like this
debug_app = DebuggedApplication(app, evalex=True)
debug_app.trusted_hosts = [...] # your own hosts here, or from django config
# somehow tell the django dev server to run this app instead |
Beta Was this translation helpful? Give feedback.
-
Perfect! that's exactly that! I was close to the solution. On my side, it's more:
Thanks ! |
Beta Was this translation helpful? Give feedback.
Most operating systems are now pre-configured to treat
*.localhost
as127.0.0.1
. So my strategy for using domains during local development isproject.localhost
,api.localhost
,auth.api.localhost
etc. If you use that, everything will already work.Otherwise, the debugger is implemented as WSGI middleware. I'm not entirely sure how to add WSGI middleware to Django (as opposed to Django middelware), but it's definitely possible.