Reputation: 654
I have a django app through which I would like to serve an index.html file. This html file isn't in default django template, rather I have the index.html in a react build folder. I don't want to render the template, rather I want to send it. The render method isn't working, and I don't know if there is any django method that can serve the file. What I want to accomplish can be done using res.sendFile()
in expressjs.
def home(request):
return FileResponse(request, 'home/home.html')
The FileResponse method isn't working here.
Upvotes: 0
Views: 2305
Reputation: 1192
FileResponse has a single required argument, an open file-like object.
This means you should not provide request
to it. On the other hand, you need to open()
the file yourself (preferably in binary mode) instead of just providing its path.
def home(request):
return FileResponse(open('home/home.html', 'rb'))
Upvotes: 0