read text file using python and display its output to html using django - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: read text file using python and display its output to html using django (/thread-4103.html) |
read text file using python and display its output to html using django - amit - Jul-23-2017 Inside Django/views.py. i added function to read a file and display o/p in newhtml file . what code is needed for this ?logic to change color at run time when each line o/p is getting displayed in html ++++++++ def main(request): #Open the file back and read the contents f=open("amit.txt", "r") if f.mode == 'r': contents =f.read() print (contents) #or, readlines reads the individual line into a list fl =f.readlines() for x in fl: print (x) return render(request,'first_app/main.html')Requirement is 1) i want to read a text file and display the output in main.html then how to spool print(x) in main.html. 2. Every line returned from Print x should have different color ( will use css file). how to change color at run time for every line coming from for loop and then spool this result in main.html Thanks Amit |