Python Forum

Full Version: read text file using python and display its output to html using django
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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