开发者

cgi URL forwarding with "Location" header - only partial forwarding?

Greetings all,

I have a python CGI script which using

print "Location: [nextfilename]"
print

After "forwarding" (the reason for the quotes there is apparent in a second), I see the HTML of the page to which it has forwarded fine, but all images, etc. are not showing. The address bar still shows the cgi script as the current location, not the HTML file itself. If I go to the HTML file directly, it displays fine.

Basically, the CGI script, which is stored in the cgi-bin, whereas the HTML files are not, is trying to render images with relational links that are broken.

How do I actually forward to the next page, not just render the next page through the cgi script?

I have gone through the script with a fine-toothed comb to make sure that i wasn't actually using a print htmlDoc command anywhere that would be interrupting and screwing this up.

Sections of Code that are Applicable:

def get_nextStepName():
        """Generates a random filename."""
开发者_JAVA技巧        nextStepBuilder  = ["../htdocs/bcc/"]
        fileLength = random.randrange(10)+5
        for i in range(fileLength):
                j = random.choice(varLists.ALPHANUM)
                nextStepBuilder.append(j)
        nextStepName = ""
        for char in nextStepBuilder:
                nextStepName += char
        nextStepName += ".html"
        return nextStepName

def make_step2(user, password, email, headerContent, mainContent, sideSetup, sideContent, footerContent):
        """Creates the next step of user registration and logs valid data to a pickle for later confirmation."""
        nextStepName = get_nextStepName()
        mainContent = "<h1>Step Two: The Nitty Gritty</h1>"
        mainContent += "<p>User Name: %s </p>" % (user)
        mainContent += """\
               [HTML CODE GOES HERE]
                        """
        htmlDoc = htmlGlue.glue(headerContent, mainContent, sideSetup, sideContent, footerContent)
        f = open(nextStepName, "w")
        f.write(htmlDoc)
        f.close()

        nextStepName = nextStepName[9:] #truncates the ../htdocs part of the filename to fix a relational link issue when redirecting
        gotoNext(nextStepName)

def gotoNext(filename):
        nextLocation = "Location:"
        nextLocation += filename
        print(nextLocation)
        print

Any thoughts? Thanks a ton. CGI is new to me.


You need to send a 30X Status header as well. See RFC 2616 for details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜