Programmer's Corner Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Programmer's Corner - Forums


Wierd behavior - Different page being served up.

 
Post new topic   Reply to topic    Programmer's Corner Forum Index -> Python
Author Message
Cerulean
Gokenin


Joined: 22 Oct 2004
Posts: 742
Location: London, England

PostPosted: Tue Nov 02, 2004 4:06 pm    Post subject: Wierd behavior - Different page being served up. Reply with quote

Okay, so I have a python script to serve up my webpage which provides a list of programs. Its in Python because it makes it obscenely easy to add new entries to it - just type up the description and the formatting is done automatically.
Now, for some very peculiar reason, if I access that page (/programs/index.py), sometimes it works. Other times though it serves up pages in /programs/phpbb2rss/index.py and in the url box still says that its /programs/index.py, or sometimes it will serve up /programs/azure/index.py and say that its /programs/index.py. Really wierd behavior.
I use no page forwarding anywhere on /progams/index.py, so i'm just completely confused.

To test it out, just go along to http://cerulean.pyresoft.com and click on the Programs link a few times. You'll see what I mean.

Here is /progams/index.py with lots of the html just taken away.

Code:

#!/usr/bin/python
from mod_python import apache

includes = apache.import_module("includes", log=1)
# iefix, navigation

def index(req):
   currentpage = "Programs"
   
   programs = []
   # Title then body.
   
   programs.append("pyrcbot: A simple, easy-to-understand IRC bot written in Python." + """
   As the  ... extendable.""")
   
   programs.append("phpbb2rss: Convert a phpBB forum page into an RSS feed." + """
   Converts ...... making of this program.""")
   
   programs.append("Azure: A web bot that crawls the net." + """
   ........
   other than crawl the web, following anchor tags though...""")
   
   ####
   
   req.content_type = "text/html"
   req.write("""
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   
<head>
<title>Cerulean - Programs</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" type="text/css" href="/css/styles.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="/blosxom.cgi/index.rss" />
<link rel="alternate" type="application/atom+xml" title="Atom" href="/blosxom.cgi/index.atom" />
""")
   
   # Fix ie problems if the browser is ie.
   req.write(includes.iefix(req))

   req.write("""
</head>

<body>
<div id="container">
<div id="centered">

   <div id="banner" title="Cerulean - Prelude of thoughts">
   &nbsp;
   </div>

   <div id="center">
   
   <div id="menu">
   <ul id="navigation">
""")

   req.write(includes.navigation(currentpage))

   req.write("""</ul>
   </div>
   <br style="font-size: 8px" />
   <h3 class="posttitle" style="background: transparent">Programs</h3><br />
   ....
   Hope they're of use to someone.<br /><br />
   </p>""")
   
   for program in programs:
      output = ""
      header = ""
      headerend = program.find("\n")
      linkend = program.find(":")
      if headerend == -1 or linkend == -1:
         output = "Bad entry"
         break
      header = program[linkend:headerend]
      body = program[headerend + 1:]
      output = "<p class=\"posttext\"><a href=\"" + program[0:linkend].lower() + "/\"><strong>" + program[0:linkend] + "</strong></a>" + header + "<br />" + body + "<br /><br /></p>\n\n"
      req.write(output)
   
   
   req.write("""
         </div>

         <div id="footer">
........
   </div>
</body>

</html>""")
Back to top
Algorithms
Dragon


Joined: 21 Oct 2004
Posts: 343
Location: Florida

PostPosted: Tue Nov 02, 2004 4:17 pm    Post subject: Reply with quote

mod_python generates pyc's for modules in a directory that apache can access. The problem is all your modules are named the same thing which causes the call to index to become ambiguous.
Back to top
Cerulean
Gokenin


Joined: 22 Oct 2004
Posts: 742
Location: London, England

PostPosted: Tue Nov 02, 2004 4:22 pm    Post subject: Reply with quote

Oh wow, it was a simple answer. I was worried and started hacking away at the file.
Thanks alot Algorithms. Is there a simple solution, which will allow me to use index.py? If not, no harm done. I'd much rather have the pyc and rename each file.
Back to top
Cerulean
Gokenin


Joined: 22 Oct 2004
Posts: 742
Location: London, England

PostPosted: Tue Nov 02, 2004 4:29 pm    Post subject: Reply with quote

I see i'll have to use different sub-interpereters, which seems a bit of an overkill for such a little thing. I'll just rename.
Cheers again.
Back to top
Algorithms
Dragon


Joined: 21 Oct 2004
Posts: 343
Location: Florida

PostPosted: Tue Nov 02, 2004 8:15 pm    Post subject: Reply with quote

I just write a simple load script called index.py where index.py?fetch=whatever.py would then call the fetch method which returns the file requested.
Back to top
Cerulean
Gokenin


Joined: 22 Oct 2004
Posts: 742
Location: London, England

PostPosted: Wed Nov 03, 2004 5:08 am    Post subject: Reply with quote

Thats sort of what I did. Instead of making different files just make what was a file into a different module, so file.py/file. Works well.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Programmer's Corner Forum Index -> Python All times are GMT - 5 Hours
Page 1 of 1

 


Powered by phpBB © 2001, 2002 phpBB Group