【发布时间】:2016-07-21 23:09:38
【问题描述】:
我正在为计算语言学项目编写一个小型门户网站,使用户能够注释一些文本,并将他们的注释保存到文件中。
我无法保存修改后的文本。
我的页面是:
from bottle import template
from project import app
from bottle import request
from bottle import redirect
import random
@app.route('/')
def index():
notices = 'This is a placeholder text for StackOverflow'
return template('annotator/index', package=notices)
@app.route('/annotator/submit', method=['GET'])
def submit():
with open('output.txt', 'w') as outfile:
package = str(request.GET.get('package'))
outfile.write(str(package))
redirect('/')
我的页面布局是:
<!doctype html>
<head>
<link rel="stylesheet" type="text/css" href="/css/style.css">
<title>My App</title>
</head>
<body>
<div class="page">
<h1>NM Annotator Demo V 0.1</h1>
% if package is not '':
<form action='annotator/submit', method="GET">
<textarea name="package" ROWS=20 COLS=70>{{package}}</textarea>
<td><INPUT TYPE=SUBMIT name="package" VALUE="Submit"></td>
</form>
%end
%include
</div>
</body>
提交页面是:
<form action="annotator/submit" method="post">
<dl>
Thank you
</dl>
</form>
%rebase layout/layout
但是,文件中只保存了“提交”一词 - 而不是文件的内容 - 这是我想要保存的内容,因为它将是注释的结果。
这是我的第一个网络应用程序,我有点困惑。
【问题讨论】: