protracted whine
I deploy a django site to run in Docker swarm on a corporate LAN. It appears to me that
(sometimes), after django generates html pages, something is removing part of the URL django template
generates. I am not at all sure it is a django issue, it might be something about our reverse proxy (but that doesn’t quite make sense from symptoms either).
I don’t know what to ask/investigate next.
About 50% of the time when I deploy, the .css “works”. Other times, the path to css in
the rendered page in incorrect. I “fix” the problem by redeploying without code change, and after a few tries everything’s fine, and it stays fine until next server restart or deploy, after which it’s fine roughly 50% of the time. The difference does not correspond to which node in the swam it runs on.
Below I show
- the symptom, and
- that when I investigate with
manage.py shell, it seems like the templatestatictag is working as expected. I don’t know how to verify that
django.templatetags.static.staticis actually getting called. If it’s not, my assumptions
are wrong.
Details:
1) the symptom
In my setup, the reverse proxy (nginx I think) finds the container by having
‘/bi-web-utils/daily’ preprended to root, and I set that in
settings.FORCE_SCRIPT_NAME.
My sometimes-it-works html includes:
<link rel="stylesheet" href="{% static 'tableau_explorer/header.css' %}">
Right now, “it’s not working” and my rendered page shows
<link rel="stylesheet" href="/static/tableau_explorer/popup.css"> (missing the FORCE_SCRIPT_NAME.`
And, I have debugging html
<P>The url from evaluating static is <pre>
/static/tableau_explorer/header.css.</pre></P>
<P>What was predicted from view was: <pre>/static/tableau_explorer/header.css</pre></P>
The value “/static/tableau_explorer/header.css” is calculated in view by static('tableau_explorer/header.css') as below:
from django.templatetags.static import static
def index(request):
checkbox_defaults = {'use_acct': True,
'use_corp': True,
'use_dev': False,
}
return render(request,
template_name="tableau_explorer/index.html",
# {**d, **e} returns the merged dictionaries d & e
context={
**{'workbook_search_form': IndexPageSearchForm(prefix='WB'),
'everything_search_form': IndexPageSearchForm(prefix='EV') },
**checkbox_defaults,
**dict(predicted_url=static('tableau_explorer/header.css'))
})
2) the static method is getting the value I would expect if I examine it in the shell:
Inside Django shell of the running container everything looks like I would expect it to look:
>>> from django.templatetags import static
>>> static.static(
>>> static.static("tableau_explorer/index.html")
'/bi-web-utils/daily/static/tableau_explorer/index.html'
>>> settings.FORCE_SCRIPT_NAME
'/bi-web-utils/daily/'