FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Using embedded HTML in Python?





Stay_Classy
In PHP, you can use regular HTML, and PHP will just run everything between the <?php and ?> tags. Is something like this possible in Python? It seems to me like this could be done with regular expressions and eval/exec, but that would require directing everything through one python module, and would cause high CPU load and long response times.

Is there a better way to do this?
jgsedi
At PHP and HTML the webserver is capable of interpret the PHP-Snippets in the file. So a machine is necessary to interpret embedded code.

For Python i don't know a system which can do that

In Python there is another way to achieve the same result: use python (the interpreter) to create embedded html-snippets:

An example in Python:
Code:
# the content for the frame
this_is_the_body_content="This text is seen in the Browser..."

# htmltext is a html-frame to fill with some content
htmltext="""
<html>
  <body>
  %s
  </body>
</html>""" % (this_is_the_body_content,)

# output of htmltext
print htmltext


The python module string has a template function with exactly that purpose
(https://docs.python.org/2/library/string.html#template-strings)
astrobyte
Yes, you can use python on your web, you an use a framework like django or you can use cgi.

Here is a tutorial about using python with cgi:

http://www.tutorialspoint.com/python/python_cgi_programming.htm[/url]
Related topics
Complete Tutorial LINKS for every language
Hacker-proof site without php?
DreamWeaver or Visual Studio
What Web Design Software is everyone using?
python n00b
Using Image Shack for my Sig file
Displaying .txt file on web page
Best :: HTML Editor ::
Python
Python help
Python: Sequences
Python: Changing a string (Assignment)
help python
Python and SQLite
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.