Connecting Tech Pros Worldwide Forums | Help | Site Map

Wed Development - Dynamically Generated News Index

infidel02@lycos.com
Guest
 
Posts: n/a
#1: Dec 18 '05
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,


Paul Rubin
Guest
 
Posts: n/a
#2: Dec 18 '05

re: Wed Development - Dynamically Generated News Index


infidel02@lycos.com writes:[color=blue]
> 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.[/color]

Why don't you look at Django, which was built for that purpose.
gene tani
Guest
 
Posts: n/a
#3: Dec 18 '05

re: Wed Development - Dynamically Generated News Index



Paul Rubin wrote:[color=blue]
> infidel02@lycos.com writes:[color=green]
> > 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.[/color]
>
> Why don't you look at Django, which was built for that purpose.[/color]

(lots of funny pictures )
http://www.holovaty.com/images/presentation.pdf

infidel02@lycos.com
Guest
 
Posts: n/a
#4: Dec 18 '05

re: Wed Development - Dynamically Generated News Index


Hi Jean-Paul,

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

infidel02@lycos.com
Guest
 
Posts: n/a
#5: Dec 20 '05

re: Wed Development - Dynamically Generated News Index


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>

Steve Holden
Guest
 
Posts: n/a
#6: Dec 20 '05

re: Wed Development - Dynamically Generated News Index


infidel02@lycos.com wrote:[color=blue]
> 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[/color]

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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

infidel02@lycos.com
Guest
 
Posts: n/a
#7: Dec 20 '05

re: Wed Development - Dynamically Generated News Index


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>

infidel02@lycos.com
Guest
 
Posts: n/a
#8: Dec 21 '05

re: Wed Development - Dynamically Generated News Index


Thank Steve this worked!

Closed Thread