- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在 Pylons 中创建一个网络应用程序,并且正在进行图像上传操作。目前正在我的 Windows 机器上使用 egg:paste#http 运行,使用 pylons 文档快速入门中描述的基本开发配置。
当我将图像发布到我的应用程序,然后将图像移动到网络根目录,然后将上传的图像拉到浏览器中时,图像出现扭曲。这是我上传 Yahoo! 的 GIF 时得到的结果 Logo ,但大多数文件根本不显示在浏览器中,可能是因为损坏:
distorted yahoo logo http://www.freeimagehosting.net/uploads/d2c92aef00.png
这是我正在使用的基本代码(直接来自 pylons 文档):
os_path = os.path.join(config.images_dir, request.POST['image'].filename)
save_file = open(os_path, 'w')
shutil.copyfileobj(request.POST['image'].file, save_file)
request.POST['image'].file.close()
save_file.close()
request.POST['image'] 是一个 cgi.FieldStorage 对象。我认为这可能是 Windows 行结尾的问题,但我不确定如何检查或更正它。是什么导致我上传的图片失真/损坏?
最佳答案
您可能只是缺少有效地将文件写入二进制文件的“b”(二进制)标志:
save_file = open(os_path, 'wb')
但我不明白为什么你需要 shutil.copyfileobj
调用,为什么不这样做:
file_save_path = os.path.join(config.images_dir, request.POST['image'].filename)
file_contents = request.POST['image'].file.read()
# insert sanity checks here...
save_file = open(file_save_path, 'wb')
save_file.write(file_contents)
save_file.close()
或者使最后三行更像 pythonic(确保即使写入失败也关闭文件句柄):
with open(file_save_path, 'wb') as save_file:
save_file.write(file_contents)
你可能需要一个
from __future__ import with_statements
如果您使用的是 Python 2.6,则位于文件顶部。
关于python - Pylons 在 Windows 上上传扭曲的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2113126/
我知道 Pylons 已停产并导入到 Pyramid。然而,我真的很喜欢学习 Pylons 并且无法通过 Pyramid(这还为时过早并且缺乏对初学者友好的文档)所以我开始阅读 online Pylo
在django中,我们可以执行以下操作: views.py : def A(request): context = {test : 'test'} return
我按照应用程序运行 pylons 项目的测试: http://pylonshq.com/docs/en/0.9.7/i18n/#testing-the-application 但是当我运行时: no
我正在尝试设置 celery 和 pylons,但似乎无法正常工作。我下载了 pylons-celery,但是如何将我的 Pylons 环境指向 celeryconfig.py 所在的位置?我将配置文
我有一个基于 pylons 的 webapp,我很想在一段时间内使用 celery + rabbitmq 来完成任务。我已经查看了 celery-pylons 项目,但我没有成功使用它。 我对 cel
我想为连接到我的 Web 应用程序(用 Pylons 编写)的每个浏览器跟踪一个唯一标识符。我在客户端保留一个 cookie 来跟踪这个,但如果 cookie 不存在,然后我想生成一个新的唯一标识符,
这就是我发现理论上应该从 git hub.compassenger-pylons-wsgi-example 工作的内容 import os, sys
我试图将公司模块导入我的软件,但出现错误: ImportError: No module named config 来自: from pylons.config import config 很明显,我
我正在研究 Pylons 并想知道,我应该使用 Paste 作为网络服务器还是可以使用 Apache? 使用粘贴有什么优势吗? 您会建议不要使用 Apache 吗? 我应该如何托管网站? 最佳答案 我
当我尝试在虚拟 python 环境中导入 pylons 时出现错误 C:\env\Scripts>python Python 2.7 (r27:82525, Jul 4 2010, 07:43:08
更新:这只是 Pylons 应用程序中的一个导入错误(因为 $PYTHONPATH 在运行已启动的作业时不同)导致了失败重生周期。非常感谢那些告诉我查看日志的人。 大家好 我在 OS X 上,试图设置
有没有一种真正的方法可以在 Pylons 中添加身份验证?我见过很多不同的方法,但大多数方法要么过时,要么过于复杂。是否有教程可以解释如何以良好而可靠的方式添加身份验证? 最佳答案 考虑使用 repo
我正在考虑是否应该在我的项目中使用 Turbogears 或 Pylons。我知道 Turbogears2 基于 Pylons。 Turbogears 提供了 Pylon 没有的什么? 谢谢。 最佳答
我正在评估一些 Web 应用程序框架,最后,两个最大的竞争者(在我看来)是 Ruby on Rails 和 Pylons。为了在不花费太多时间的情况下更好地理解这两个框架,我决定在一个框架上遵循一个重
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
from decorator import decorator from pylons.decorators.util import get_pylons def allowed_roles(role
有没有办法创建一个中间件来捕获每个引发的异常并将堆栈跟踪打印到 Pylons 框架中的日志和标准输出(可能带有一些附加信息)? 最佳答案 标准paste.exceptions.errormiddlew
Only comments associated with the current page should be listed, so once again the query is modified
我有一个旧项目,它是在 Python 2.5/2.6、Windows 下编写的。 我们现在有 Python 2.6/Win7/x64,我试着启动它。我得到了在服务器上运行非 Debug模式的旧项目,并
我正在运行 Pylons ,我这样做了:粘贴服务器开发.ini它在 :5000 上运行 但是当我再次尝试运行命令时:粘贴服务 development.ini 我收到这条消息:socket.error:
我是一名优秀的程序员,十分优秀!