473,396 Members | 2,089 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,396 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 6565
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.