Closed ovalseven8 closed 4 years ago
One solution is
config('SECURE_PROXY_SSL_HEADER', default=None, cast=lambda s: Csv(post_process=tuple).__call__ if s else None)
However, that looks hacky. Is not there a better way?
So this is clearly a design mistake in Django. Instead of None it should use an empty tuple.
So to work around in a (maybe) less hacky form trye:
SECURE_PROXY_SSL_HEADER = config('SECURE_PROXY_SSL_HEADER', default='', cast=Csv(post_process=tuple)) or None
Also, decouple simplicity encourages you to express what make sense for your domain and you could also do:
def header(s, cast=Csv(post_process=tuple)):
return cast(s) or None
config('SECURE_PROXY_SSL_HEADER', default='', cast=header)
Then you could have a collection of cast
helpers for your domain.
In my settings file I have:
Now, when I want to set the header on one of my projects, everything is fine. I just put the following in my
.env
file:However, when I do not need this header in another project, it does not work. Because if I leave empty, the default value is
None
and that conflicts withcast=Csv(post_process=tuple)
.