22π
Try the following:
def featured(request):
content = '<html>test123</html>'
response = HttpResponse(content, content_type='application/liquid')
response['Content-Length'] = len(content)
return response
A quick tip, you could add this into the http
or server
block part of your NGINX configuration so you donβt have to specify the encoding within views and other Django code:
charset utf-8;
charset_types text/css application/json text/plain application/liquid;
π€Matt
5π
So this worked for me:
def featured(request):
response = HttpResponse("", content_type="application/liquid; charset=utf-8")
response['Content-Length'] = len(content)
response.write('<html>test123</html>')
return response
Thanks, everyone, for the help!
π€winter
- [Django]-Import csv data into database in Django Admin
- [Django]-Usage of .to_representation() and .to_internal_value in django-rest-framework?
- [Django]-Import "rest_framework" could not be resolved. But I have installed djangorestframework, I don't know what is going wrong
4π
Following the instructions from the docs it should be something like this:
# set content_type
response = HttpResponse("",
content_type="application/liquid; charset=utf-8")
# add content
response.write('<html>test123</html>')
Hope this helps!
π€Paulo Bu
- [Django]-Django development server reload takes too long
- [Django]-_() or {% trans %} in Django templates?
- [Django]-Unable to import path from django.urls
3π
Just to expand the other answers, if the HttpResponse
object already exists and its MIME type needs to be set after instantiating it (for example, when invoking a parent method), it can be achieved this way:
response = super(...) # This returns some HttpResponse object
response["Content-Type"] = "application/liquid"
return response
π€LostMyGlasses
- [Django]-How can I use the variables from "views.py" in JavasScript, "<script></script>" in a Django template?
- [Django]-PIL /JPEG Library: "decoder jpeg not available"
- [Django]-VS Code error when importing Django module
Source:stackexchange.com