4👍
There is a TemplateResponse response class which takes the same parameters as direct_to_template shortcut. You can just replace and be safe
return TemplateResponse(request, template)
3👍
The render
shortcut can be used as a replacement for direct_to_template
for this usage. It takes the same parameters as direct_to_template
so it can be a simple find and replace.
return direct_to_template(request, template)
becomes
return render(request, template)
- [Django]-Int vs String for field choices
- [Django]-Csrf issue from node js to django
- [Django]-Getting time of form submission in Django
2👍
In general you don’t have to explicitly return a TemplateView like that, you just put it in your urls and you’re done with it.
Now, the reason you don’t get a response with a Post is that TemplateView only defines a GET method
So you would need to create a new class that inherits from TemplateView in order to implement a POST method yourself.
My recommendation would be to look for the other CBV and see if one matches your needs better, perhaps a FormView would suffice
https://github.com/django/django/blob/master/django/views/generic/base.py#L147
- [Django]-Setting global variables with Cactus App for Mac
- [Django]-Checking if image exists – Django (1.3)
- [Django]-Kubernetes liveness probe fails when the logs show a 200 response