web2py查看错误
我是 web2py 的新手,我必须编写一个文件上传脚本。
现在通过互联网搜索我找到了一个脚本,它可以在我的 cmp 本地运行 将其放入服务器后,我得到无效视图(uploda_zipa/upload_file.html)
代码是:
import datetime
timestamp = datetime.datetime.today()
db.define_table('files',
Field('title', 'string'),
Field('uploaded_data', 'upload'),
Field('created_on','datetime',default=timestamp))
db.files.title.requires = IS_NOT_EMPTY()
db.files.uploaded_data.requires = IS_NOT_EMPTY()
#Now, lets add an action the our controller
def upload_file():
url = ""
form = SQLFORM(db.files, showid=False)
if form.accepts(request.vars, session):
response.flash = T('File uploaded successfully!')
url = URL(r=request, f="download",
args = db(db.files.title == request.vars.title).select(orderby=~db.files.created_on)[0].uploaded_data)
return dict(form=form, cknum=request.vars.CKEditorFuncNum, url=url)
我还想知道如何设置应上传文件的文件夹的路径,或者是默认方式。该计划就像一个文件被上传到特定文件夹,然后由不同的脚本处理,
谢谢
I am new to web2py and I have to write a file upload script.
now searching trough internets i found a script and it kind of works local on my cmp
After putting it to server i get invalid view (uploda_zipa/upload_file.html)
The code is:
import datetime
timestamp = datetime.datetime.today()
db.define_table('files',
Field('title', 'string'),
Field('uploaded_data', 'upload'),
Field('created_on','datetime',default=timestamp))
db.files.title.requires = IS_NOT_EMPTY()
db.files.uploaded_data.requires = IS_NOT_EMPTY()
#Now, lets add an action the our controller
def upload_file():
url = ""
form = SQLFORM(db.files, showid=False)
if form.accepts(request.vars, session):
response.flash = T('File uploaded successfully!')
url = URL(r=request, f="download",
args = db(db.files.title == request.vars.title).select(orderby=~db.files.created_on)[0].uploaded_data)
return dict(form=form, cknum=request.vars.CKEditorFuncNum, url=url)
I would also like to know how to set path for folder in which files should be uploaded or is that default way. The plan is smth like a file gets uploaded to a specific folder and than it gets processed by a different script
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您没有定义“upload_file.html”视图,web2py 将回退到使用“generic.html”视图。但是,默认情况下,通用视图仅在本地主机上启用,因此这可能解释了为什么它可以在本地计算机上运行,但不能上传到服务器。出于安全原因,建议您不要在生产中启用通用视图,或者至少明智地这样做。有关更多详细信息,请参阅此处。
至于上传文件夹,默认为/yourapp/uploads,但您可以按如下方式更改:
参见
Field()
的参数。If you do not have an 'upload_file.html' view defined, web2py will fall back to using the 'generic.html' view. However, by default, the generic views are only enabled on localhost, so that probably explains why it worked on your local computer but not once uploaded to the server. For security reasons, it is recommended that you not enable generic views on production, or at least that you do so judiciously. See here for more details.
As for the upload folder, it defaults to /yourapp/uploads, though you can change it as follows:
See the explanation of
uploadfolder
in the list of arguments toField()
.