Wed Development - Dynamically Generated News Index

I

infidel02

Hi to all,

I am somewhat somewhat new to Python, but apart from this I am just not
seeing lots of resources on what I am trying to do. I have seen them
in other languages like PHP and ASP.

I am building a simple MySQL news database, which would contain, a
headline, a date, main story(body) and a graphic associated with each
story. I would like to generate an index of the pages in this database
( ie a news index with links to the articles) an to have a news
administrator upload and delete stories graphic etc.

I have read many articles on Python CGI programming and I have Googled
extensively, but have not seen any kind of examples of how this can be
done in Python.

I would be grateful for any assistance or pointers.

Sincerely,
 
P

Paul Rubin

I am building a simple MySQL news database, which would contain, a
headline, a date, main story(body) and a graphic associated with each
story. I would like to generate an index of the pages in this database
( ie a news index with links to the articles) an to have a news
administrator upload and delete stories graphic etc.

Why don't you look at Django, which was built for that purpose.
 
I

infidel02

Hi Jean-Paul,

I am a bit lost in you code. Is it possible for you to step through
it?
 
I

infidel02

Hi Jean-Paul,

The truth of the matter is that I was hoping that this could be
accomplished using pure CGI.

I am considering wether I need to learn these new frameworks, but I am
in somewhat of a hurry.

Also I have this problem with this simple test script that I have
written. It pulls the infromation from the database correctly, but is
printing out the html tags in the browser, not sure what is wrong:

Script

#!/usr/bin/python

# import MySQL module
import MySQLdb, cgi

# connect
db = MySQLdb.connect(host="localhost", user="nancy",
passwd="intentions",
db="ardDB")

# create a cursor
cursor = db.cursor()

# execute SQL statement
cursor.execute("SELECT * FROM news where storyDATE < '2005-10-1';")

# get the resultset as a tuple
result = cursor.fetchall()

db.close()

print """ Content-Type: text/html\n\n
<html>
<head>

<title>DB Test</tile>

</head>

<body>

"""

# iterate through resultset
for record in result:

print """<h1>%s</h1>

<p>%s</p>

<p>%s<p>

""" %(record[1],record[2],record[3])




print """

</body>

</html>

"""


Results:


<html>
<head>

<title>DB Test</tile>

</head>

<body>


<h1>Heading 4</h1>

<p>Body 4</p>

<p>2005-09-01<p>


<h1>Heading 5</h1>

<p>Body 5</p>

<p>2005-09-10<p>


<h1>Heading 6</h1>

<p>Body 6</p>

<p>2005-09-12<p>




</body>

</html>
 
S

Steve Holden

Hi Jean-Paul,

The truth of the matter is that I was hoping that this could be
accomplished using pure CGI.

I am considering wether I need to learn these new frameworks, but I am
in somewhat of a hurry.

Also I have this problem with this simple test script that I have
written. It pulls the infromation from the database correctly, but is
printing out the html tags in the browser, not sure what is wrong:

Script

#!/usr/bin/python

# import MySQL module
import MySQLdb, cgi

# connect
db = MySQLdb.connect(host="localhost", user="nancy",
passwd="intentions",
db="ardDB")

# create a cursor
cursor = db.cursor()

# execute SQL statement
cursor.execute("SELECT * FROM news where storyDATE < '2005-10-1';")

# get the resultset as a tuple
result = cursor.fetchall()

db.close()

print """ Content-Type: text/html\n\n

Your problem is that space before the HTTP header. Get rid of that and
you'll probably find that the browser recognises your output as HTML. Try

print """Content-Type: text/html\r\n\r\n ...

regards
Steve
 
I

infidel02

Hi Jean-Paul,

The truth of the matter is that I was hoping that this could be
accomplished using pure CGI.

I am considering wether I need to learn these new frameworks, but I am
in somewhat of a hurry.

Also I have this problem with this simple test script that I have
written. It pulls the infromation from the database correctly, but is
printing out the html tags in the browser, not sure what is wrong:

Script

#!/usr/bin/python

# import MySQL module
import MySQLdb, cgi

# connect
db = MySQLdb.connect(host="localhost", user="nancy",
passwd="intentions",
db="ardDB")

# create a cursor
cursor = db.cursor()

# execute SQL statement
cursor.execute("SELECT * FROM news where storyDATE < '2005-10-1';")

# get the resultset as a tuple
result = cursor.fetchall()

db.close()

print """ Content-Type: text/html\n\n
<html>
<head>

<title>DB Test</tile>

</head>

<body>

"""

# iterate through resultset
for record in result:

print """<h1>%s</h1>

<p>%s</p>

<p>%s<p>

""" %(record[1],record[2],record[3])




print """

</body>

</html>

"""


Results:


<html>
<head>

<title>DB Test</tile>

</head>

<body>


<h1>Heading 4</h1>

<p>Body 4</p>

<p>2005-09-01<p>


<h1>Heading 5</h1>

<p>Body 5</p>

<p>2005-09-10<p>


<h1>Heading 6</h1>

<p>Body 6</p>

<p>2005-09-12<p>




</body>

</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,274
Messages
2,571,366
Members
48,058
Latest member
ShellieMac

Latest Threads

Top