-1

xampp running a python script that writes an html file. How do i get xampp to serve the html from python.

name = "david"
age = 44
square = age**0.5
HTML=f"""
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Download</title>
</head>
<body>
    {name} age is {age} but he is square so age is{square}
</body>
</html>
"""
with open("test.html","w") as new_file:
    new_file.write(HTML)

This writes test.html how do i ask xampp to display

1
  • it is not clear what you're trying to achieve. the point of dynamic content is to avoid writing it to the drive Commented Nov 6, 2024 at 22:11

1 Answer 1

0

After generating the document test.html (typically located at C:\xampp\htdocs\test.html or where your xampp is installed), simply try to access it using the address http://localhost/test.html

Edit: Added following code

Can you try this now:

#!/usr/bin/env python3

import cgi

name = "david"
age = 44
square = age**0.5
HTML=f"""
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Dynamic Output</title>
</head>
<body>
    <p>{name} age is {age} but he is square so age is {square}</p>
</body>
</html>
"""

# for output
print("Content-Type: text/html\n")
print(HTML)
Sign up to request clarification or add additional context in comments.

8 Comments

The answer is not answering the question. Its how do I get the test.html to be served by xampp immediately upon the write of the html to display in localhost with no intervention from the user.
XAMPP serves files from the htdocs folder by default
or you may want to open that via a web browser after running the script?
BTW, did you change your document's path (with open("test.html","w") in your code) to the correct one as I described?
xampp is already running so that wont work, trying to display resulting html without typing localhost ie restarting the browser session. so i need some code to do that. Quote--"xampp to serve the html from python".
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.