当我尝试使用此pylons脚本上传时,我一直收到KeyError:'permanent_store'错误
我的控制器
类UploadController(BaseController):
def index(self):
return render('/uploadform.html')
def upload(self):
myfile = request.POST['myfile']
permanent_file = open(
os.path.join(
config['app_conf']['permanent_store'],
myfile.filename.replace(os.sep,'_')
),
'wb'
)
shutil.copyfileobj(myfile.file, permanent_file)
myfile.file.close()
permanent_file.close()
return "Uploaded %s, description: %s" % (
myfile.filename,
request.POST['description']
)
def download(self):
requested_filename = request.params['requested_filename']
filename = os.path.join (
config['app_conf']['permanent_store'],
requested_filename.replace(os.sep, '_')
)
if not os.path.exists(filename):
return "No such file"
permanent_file = open(filename, 'rb')
data = permanent_file.read()
permanent_file.close()
response.content_type = guess_type(filename)[0] or 'text/plain'
return data
这是我的development.ini
的一部分[app:main]
use = egg:FormDemo
full_stack = true
static_files = true
permanent_store = %(here)s/data/uploads
由于与permanent_store有关,我无法上传或下载文件。