我正在爲我的項目使用webpy框架。我想從我的webpy程序傳遞一個文件並將其顯示在html頁面上(文件可能是任何文本文件/程序文件)。我使用了我的webpy程序中的以下函數傳遞了一個文本文件。在HTML頁面上顯示文件,因爲它是
class display_files:
def GET(self):
wp=web.input()
file_name=wp.name
repo_name=wp.repo
repo_path=os.path.join('repos',repo_name)
file_path=os.path.join(repo_path,file_name)
fp=open(file_path,'rU') #reading file from file path
text=fp.read() #no problem found till this line.
fp.close()
return render.file_display(text) #calling file_display.html
當我試圖顯示文件(這裏是「文」),從「file_display.html」,它不斷地顯示不承認newline.Here是我的HTML文件。
$def with(content)
<html>
<head>
<meta http-equiv="Content-Type" content="text/string;charset=utf-8" >
<title>File content</title>
</head>
<body>
<form name="file_content" id="file_content" methode="GET">
<p> $content</p>
</form>
</body>
<html>
如何顯示文件,因爲它是在HTML頁面。
非常感謝Helgi。你的回答是絕對正確的。也感謝約瑟的回答。 – Unni