Python Forum
read text file using python and display its output to html using django
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read text file using python and display its output to html using django
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask, read H5 text value tantony 4 1,391 Oct-31-2022, 05:29 PM
Last Post: tantony
Lightbulb Python Obstacles | Kung-Fu | Full File HTML Document Scrape and Store it in MariaDB BrandonKastning 5 2,817 Dec-29-2021, 02:26 AM
Last Post: BrandonKastning
  show csv file in flask template.html rr28rizal 8 34,521 Apr-12-2021, 09:24 AM
Last Post: adamabusamra
Lightbulb Hypertag. New language for HTML templating w/ Django support mwojnars 0 1,739 Apr-06-2021, 12:53 PM
Last Post: mwojnars
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,529 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  Scrape for html based on url string and output into csv dana 13 5,326 Jan-13-2021, 03:52 PM
Last Post: snippsat
  creating an exe file for a python django project Sanjish 0 2,585 Dec-27-2020, 07:33 AM
Last Post: Sanjish
  Any way to remove HTML tags from scraped data? (I want text only) SeBz2020uk 1 3,410 Nov-02-2020, 08:12 PM
Last Post: Larz60+
  Open and read a tab delimited file from html using python cgi luffy 2 2,633 Aug-24-2020, 06:25 AM
Last Post: luffy
  How to display XML tree structure with Python? sonicblind 13 41,835 Aug-12-2020, 02:05 PM
Last Post: mreshko

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020