How can i edit .txt file in browser in django?

(Mit Patel) #1

after load the txt file in django template through iframe tag how can i edit the .txt file in browser and download the file?
iframe src="{{ page.txt_page_path }}" style=“height:100%;width:100%”

(Basil Jose) #2

Instead of trying to deal with DTL use simple java-script to achieve the same with less effort.
here is an example you can refer edit text file

(Mit Patel) #3

Yes I can do this but i don’t want to upload file, the file which is display in browser is coming from particular file path like you can assume that we set the static folder in user system so from that folder the file is render in browser after this process is complete if user want to edit the file than it’s available for the edit,Hope you getting my point. Thanks for your reply !!!

(Basil Jose) #4
getText() {
	// read text from URL location
	var request = new XMLHttpRequest();'GET', '{{ page.txt_page_path }}', true);
	request.onreadystatechange = function () {
		if (request.readyState === 4 && request.status === 200) {
			return request.responseText;

$(document).ready(function () {
	var textFromFileLoaded = getText()
	// set the read text to a textarea
	document.getElementById("show_text_here").value = textFromFileLoaded;

(Mit Patel) #5

Thankyou for your reply i will try this solution and let you know!!!

(Mit Patel) #6

Basil Jose, It’s working but it can’t display the special symbols like pound,dollar even if charset is set to utf-8.Thank you for your help