On Jul 19, 2017 1:56 PM, "Larry Martell" <larry.mart...@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.

-James

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CA%2Be%2BciXefa4vHjXtqt94sWyrvKu%2BJucj_%2BgvVyD_kf-jw7LDug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to