【发布时间】:2011-08-02 14:50:32
【问题描述】:
我正在为我的项目使用 webpy 框架。我想从我的 webpy 程序中传递一个文件并按原样显示在 html 页面上(文件可以是任何文本文件/程序文件)。我使用 webpy 程序中的以下函数传递了一个文本文件。
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”的文件(这里是“文本”)时,它会连续显示而不识别换行符。这是我的 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 页面中显示文件。
【问题讨论】: