Python Forum
SimpleHTTPRequestHandler ( verses ) Files Python Processing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SimpleHTTPRequestHandler ( verses ) Files Python Processing
#1
I am using the class (SimpleHTTPRequestHandler) to read directories and files (.html) that work perfectly well and are redenried naturally by the browser.

The problem is that I need to make files with extensions (.py) processed and sending the output in (html) so that the browser can render the received html.

I try to do this using the class (SimpleHTTPRequestHandler) and passing the path of the python file (index.py) and the result I get in the browser and the pure python code? Below is the server code and the class that returns the html:

Excerpt from the class : SimpleHTTPRequestHandler

...
class ROOTDirectory(SimpleHTTPRequestHandler):
    pass

    def do_HEAD(self):
        pass

    def do_GET(self):

        self.path = "index.py"
        # Trigger the do_GET method of the SimpleHTTPRequestHandler class
        SimpleHTTPRequestHandler.do_GET(self)
...
Class : index.py output browser :

#! /usr/local/bin/python3.9


# Class name : Index -> Structure html page :
class Index:

    # Class method : Constructor -> Object Build :
    def __init__(self):
        pass

    # Class method : build ->  : Render code html :
    def view(self):

        # Variable : v_html5 -> Code Html
        v_html5 = """
        <!DOCTYPE html>
        <html lang="pt-BR">
        <head>
            <meta charset="UTF-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Webstrucs Action</title>
        </head>
        <body>
            <h1>Action</h1>
            <p>
            Python Web Server For Asynchronous Requests<br>
            Active: active (running)<br>
            File: index.py
            </p>
        </body>
        </html>
        """
        return v_html5

o_html = Index()
o_html.view()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Processing Files that are not in use randywberry 3 675 Jun-06-2023, 06:00 PM
Last Post: rajeshgk
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,592 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  Real Time Audio Processing with Python Sound-Device not working Slartybartfast 2 3,959 Mar-14-2021, 07:20 PM
Last Post: Slartybartfast
  Image Processing in Python JoeDainton123 1 20,656 Oct-05-2020, 12:08 AM
Last Post: Larz60+
  python one line file processing har 4 3,247 Dec-09-2019, 06:10 AM
Last Post: har
  How to do real-time audio signal processing using python Zenolen 7 16,533 Nov-04-2019, 02:57 AM
Last Post: jefsummers
  Multi-processing - problem with running multiple *.py files at the same time Antonio 5 3,799 Sep-12-2018, 01:08 PM
Last Post: volcano63
  Running a python tool transforming xml files into epub files silfer 7 5,393 May-10-2018, 03:49 PM
Last Post: snippsat
  Parallel Processing in Python with Robot crcali 6 5,156 Apr-06-2018, 03:48 AM
Last Post: Larz60+
  How does multi-processing in python increase the execution time? kadsank 0 2,315 Jan-15-2018, 01:15 PM
Last Post: kadsank

Forum Jump:

User Panel Messages

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