On Thu, Jul 20, 2017 at 1:27 AM, James Schneider
<
jrschn...@gmail.com> wrote:
>
>
> On Jul 19, 2017 1:56 PM, "Larry Martell" <
larry....@gmail.com> wrote:
>
> This is probably not strictly a Django question, but I'm hoping
> someone here has had to solve this before.
>
> We have a django app that is sometimes deployed in an environment with
> SSL and talks over port 443, and other times is deployed in a non-SSL
> environment and talks over port 80. In our templates we serve CSS and
> JS files with this: href="
https://0.0.0.0:443/..." When running over
> port 80 that does not work. Is there a way to tell in the template if
> we are using port 80 or 443 and adjust the href accordingly?
>
>
> IMO this shouldn't be something you are determining on every request, it's a
> waste. You should either:
>
> A. Use relative URL's as Francois mentioned (if the request is against the
> same server). Only use absolute URL's of you need to contact a server with a
> different name.
> B. Use a custom setting in settings.py for each customer that specifies like
> RESOURCE_PREFIX = 'https://<server>/' and then use a template context
> processor to automatically populate all of your template contexts with it.
> Then it's just a matter of referencing the variable in the template combined
> with whatever path you need. They are stupid easy to write:
>
>
https://docs.djangoproject.com/en/1.11/ref/templates/api/#writing-your-own-context-processors
>
> C. Strongly encourage all of your customers to convert everything to use
> TLS, especially if any sort of credentials or sensitive data are involved.
> There's really no excuse anymore with the advent of LetsEncrypt.