简体   繁体   中英

HTML snippet from Python

I'm new to Python and CGI, so this may be trivial. But I'd like Python to produce a block of HTML whenever a visitor loads a page.

<html>
<body>
<!-- Beautiful website with great content -->

<!-- Suddenly... -->
<h1> Here's Some Python Output </h1>
<!-- RUN PYTHON SCRIPT, display output -->

</body>
</html>

Using a Python script that, for simplicity, looks something like this:

#!/usr/bin/python
print "Content-type: text/html"
print 
print "<p>Hello world!</p>"

Most resources I was able to find demonstrate how to produce an ENTIRE webpage using a Python script. Can you invoke a Python script mid-page to produce JUST an HTML snippet?

Use AJAX client-side, or templates server side.

A template will allow you to keep most of your page static, but use a server-side scripting language (like Python) to fill in the dynamic bits. There are lots of good posts on Python template systems on Stackoverflow. Here's one

AJAX will allow you to update a page after it initially loads with results from a server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM