evansd / whitenoise

Radically simplified static file serving for Python web apps
https://whitenoise.readthedocs.io
MIT License
2.51k stars 148 forks source link

`render` and `redirect` not working with Django, Gunicorn, and Whitenoise #533

Closed snackattas closed 11 months ago

snackattas commented 11 months ago

Python Version

3.10.12

Django Version

latest

Package Version

latest

Description

I went down a huge rabbithole just now, took me a day to figure out.

I was trying to use Django, gunicorn, and whitenoise.

My original views were using django shortcuts render and redirect. I think, whitenoise does not play well with those shortcuts? After lots of googling, and using chatGPT, it dawned on me that render and redirect use django's low level template engine, and maybe that doesn't play nice with whitenoise?

Once i recoded to use render_to_string and return a HttpResponse object in my views, things were working. Am I right in these statements I'm making? If so, might be nice to add something to the FAQ about this

merwok commented 11 months ago

render and redirect return HttpResponses, so it’s not that. (I would never recommend using a chatbot for questions! they only regurgitate scraped and agglomerated text)

Can you say more about your usage of whitenoise «with» these views? whitenoise is meant to serve static files, so I do not understand the setup you are describing.

snackattas commented 11 months ago

you are right, the issue was mine, the templates were not being found by render. Then i put in some other code and it worked. all my bad