473,231 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Validating Python - need doctype HTML strict


Hello,

I am trying to validate the following .py webpage as HTML (through
W3C).

I put:

-----------------------------------------------------------------------------

print "Content-type: text/html; charset=utf-8"

import time

print

print """<html><head>

<title>Current Time</title>

</head<body>

<h1>Current Time</h1>"""

print "<p>Right now, it is "

print "<strong>", time.asctime(), "</strong></p>"

print "</body></html>"

---------------------------------------------------

However, the .py page should also be valid (X)HTML - it needs a
doctype...

When I add the doctype, and other necessities to the .py page

(i.e., <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"" xml:lang="en" lang="en">)

I get an invalid script error.

Can anyone help me to get the XHTML doctype to validate and execute on
Python web page?

Thank you!

Jul 9 '06 #1
2 6553
PapaRandy wrote:
When I add the doctype, and other necessities to the .py page

(i.e., <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"" xml:lang="en" lang="en">)

I get an invalid script error.
Bear in mind, that this isn't 'a webpage', it's a computer program that
creates a webpage. So you're not 'adding a doctype', you're 'adding
some code to output a doctype', and similarly it's not Python you're
validating, it's the output it creates that you validate. These are
important distinctions.

Anyway, what is the exact line of code you use to 'add the doctype'?
And what is this 'invalid script error'? It's hard to debug your code
when we have to guess what it is! However, because I'm in a good mood,
I'll have a go.

You probably need to escape the double quotes in the doctype because
they unintentionally correspond with the double quotes in your print
statement. The print statement uses double quotes to delimit the
output, and the doctype uses them to delimit the type. Unfortunately
the print statement probably interprets the start of the doctype's type
field as the end of the print statement. Add a backslash before each
double quote within your doctype and see how that goes. Alternatively
you could possibly use single quotes in it instead.

--
Ben Sizer

Jul 10 '06 #2
Thanks Ben,

As you can see it's my first try at Python...or any programming for
that matter.

I solved the problem of validation by adding three """ quotes after the
print command and before the body, as follows:

Thanks for clearing that up!

-----------------------

import time

#print HTTP/HTML header stuff
print """Content-type: text/html; charset=utf-8\n\n

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title>Current Time</title>

</head<body>
"""

print

#print HTML body using Python-HTML hybrid script
print "<h1>Current Time</h1>"

print "<p>Right now, it is "

print "<strong>", time.asctime(), "</strong></p>"

print """<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
</p>
"""

print "</body></html>"
Ben Sizer wrote:
PapaRandy wrote:
When I add the doctype, and other necessities to the .py page

(i.e., <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"" xml:lang="en" lang="en">)

I get an invalid script error.

Bear in mind, that this isn't 'a webpage', it's a computer program that
creates a webpage. So you're not 'adding a doctype', you're 'adding
some code to output a doctype', and similarly it's not Python you're
validating, it's the output it creates that you validate. These are
important distinctions.

Anyway, what is the exact line of code you use to 'add the doctype'?
And what is this 'invalid script error'? It's hard to debug your code
when we have to guess what it is! However, because I'm in a good mood,
I'll have a go.

You probably need to escape the double quotes in the doctype because
they unintentionally correspond with the double quotes in your print
statement. The print statement uses double quotes to delimit the
output, and the doctype uses them to delimit the type. Unfortunately
the print statement probably interprets the start of the doctype's type
field as the end of the print statement. Add a backslash before each
double quote within your doctype and see how that goes. Alternatively
you could possibly use single quotes in it instead.

--
Ben Sizer
Jul 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WindAndWaves | last post by:
Hi Guys I have recently changed a site from html to php. In my HTML, I used the <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD"> header and I made...
7
by: Hansan | last post by:
Hi all, I hope you have time to help me out a little. My problem is that I want to combine some python code I have made with some html templates, I found a tutorial at dev shed:...
4
by: timmy | last post by:
I have a table with a cell on the bottom right with an image to create a rounded corner effect: <table cellpadding="0" cellspacing="0" border="1"> <tr><td rowspan="2">asdfsadf</td> <td...
0
by: LU | last post by:
Using VS.Net 03 v.7.1.3 and ASP.NET I'm geting help with javascript and the person helping me is asking me to " get rid of your XHTML ending tag slashes, use a HTML STRICT DOCTYPE" or to use the...
11
by: PatPoul | last post by:
I want to do the same thing as <script language="javascript" src="xxx.js"></script> but with a python script : <script language="Python" src="xxx.py"></script> ...
6
by: jperillo | last post by:
When I validate the source of http://www.24stores.com I'm told that I have an incorrect DOCTYPE statement. How can I, or can someone determine what I'm doing wrong !! I have no idea which...
1
by: Tatyana | last post by:
Hello, I was wondering if anybody can help to distinguish the difference (for ASP.NET pages) between I've got JavaScript Menu which I have to plug-in to the master page.
6
by: Rolf Welskes | last post by:
Hello, if I have for example: <table style="width: 100%; height: 100%;" border="1"> <tr> <td style="width: 100px">k </td> <td style="width: 100px">k </td> </tr>
8
by: jld730 | last post by:
I have been given a snippet of HTML code that I am to use Python to write it out. I am somewhat new to Python, and completely new to HTML, so I'm still unclear on what it is I am supposed to be...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.