On Thu, Jul 20, 2017 at 1:27 AM, James Schneider <[email protected]> wrote: > > > On Jul 19, 2017 1:56 PM, "Larry Martell" <[email protected]> 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.
See my reply to Francois. > 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. I agree, but I cannot control what my customers do. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACwCsY4qbWU_8SsSgoRUN-Vkw2%2BD3Mhqfg8K5jptd329jcnN_A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

