2011-04-13 19 views
0

大家好,cgi帶有「位置」標題的URL轉發 - 僅部分轉發?

我有使用

print "Location: [nextfilename]" 
print 

「轉發」後一個Python CGI腳本(引號的原因有在第二個是顯而易見的),我看到頁面的HTML它已轉發罰款,但所有圖像等沒有顯示。地址欄仍然顯示cgi腳本作爲當前位置,而不是HTML文件本身。如果我直接轉到HTML文件,它會顯示正常。

基本上,CGI腳本存儲在cgi-bin中,而HTML文件不存在,它試圖渲染斷開關係鏈接的圖像。

我如何實際上轉發到下一頁,不只是通過CGI腳本呈現下一頁?

我已經通過一個精細齒梳的腳本,以確保我實際上沒有使用打印htmlDoc命令任何地方會中斷和搞砸了。代碼的

節都適用:

def get_nextStepName(): 
     """Generates a random filename.""" 
     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 

有什麼想法?萬分感謝。 CGI對我來說是新的。

回答

2

您還需要發送30X Status標題。有關詳細信息,請參閱RFC 2616。

+0

用戶會看到此狀態消息嗎?我不希望它看起來像出了什麼問題 – 2011-04-13 16:03:20

+0

沒關係。我只是試過而不是懶惰。有效!非常感謝。 – 2011-04-13 16:07:21