Reputation: 9840
I'd like to embed the contents of a plain text file into my HTML page. The problem is that the code I have written doesn't embed it -- it starts the download automatically.
I'd like to simply embed it into the page -- and then later give someone the option to edit it. What am I doing wrong?
<div style="margin: 0 auto; width:100%; height:400px; overflow: auto;"><object type="text/html" data="{{MEDIA_URL}}{{item.content}}" style="width:100%; height:400px; margin:1%;"></object></div>
Note: {{item.content}}
inserts a .txt file.
Upvotes: 0
Views: 1085
Reputation: 13308
You're going to need to get the contents of the text file into a string or something before you pass it to your template -
def your_view(request):
#...
f = item.content.open(mode='r')
str = f.read()
return render(request, {'file_content': str})
Then access the contents in your template with {{ file_content }}
.
Upvotes: 1