我在Amazon S3上更改了一堆我的存储桶的生命周期,因此他们的存储类设置为Glacier.我是使用在线AWS控制台完成的.我现在再次需要这些文件.
我知道如何将它们恢复到每个文件的S3.但我的桶有数千个文件.我想看看是否有办法将整个桶恢复到S3,就像有办法将整个桶送到Glacier一样?
我猜有一种编程解决方案的方法.但我想知道是否有办法在控制台中执行此操作.还是用另一个程序?或者其他我可能会失踪的东西?
对于我的生活,我无法弄清楚如何使用WTForms预填充BooleanField.我有一个名为"活跃"的字段.它默认为未选中,并且不是必需的.所以我把它设置成......
class QuestionForm(Form):
question = TextField('Question', [validators.Required()])
slug = TextField('Slug', [validators.Required()])
active = BooleanField('Active')
Run Code Online (Sandbox Code Playgroud)
然后我有一个编辑页面,我在其中显示我要编辑的"问题"的表单.
{{ form.question.label }}
{{ form.question(value=q.question) }}
{{ form.active(value=q.active) }} Show this question?
Run Code Online (Sandbox Code Playgroud)
如果'active'为True,我希望BooleanField(复选框)具有'checked'属性.如果错,不要.但我甚至无法弄清楚如何使复选框具有检查状态,在渲染表单时,更不用说条件部分了.
唯一的方法,我能够让它显示检查是我在定义表单时添加default = True.但那不是我需要的.
我尝试使用'default','initial','value','selected',同时渲染表单没有运气.我搜索了文档和谷歌.我想我错过了什么!:)
UPDATE
这是我的观点.也许是问题?
@mod.route('/q/<slug>/edit', methods = ['GET', 'POST'])
def edit(slug):
form = QuestionForm(request.form, csrf_enabled=False)
q = Question.query(Question.slug==slug).get()
if request.method=='POST':
if form.validate_on_submit():
q.question = form.data.get('question')
q.slug = form.data.get('slug')
q.active = form.data.get('active')
q.put()
return redirect('/questions')
return render_template('questions/edit.html', form=form, q=q)
Run Code Online (Sandbox Code Playgroud) 我是一个python新手,开始在Google App Engine上使用Bottle Web框架.我一直在搞乱超小型,超级简单的Hello World样本,并且已经遇到了问题.嘿.我终于得到了代码来处理这个......
import bottle
from bottle import route
from google.appengine.ext.webapp import util
@route('/')
def index():
return "Hello World!"
util.run_wsgi_app(bottle.default_app())
Run Code Online (Sandbox Code Playgroud)
我的问题是,我想我可以在没有第二行的情况下去'导入瓶'.但如果我拿出第二行,我会得到一个NameError.或者如果我从'瓶子导入''',我仍然得到错误.bottle只是我网站根目录中名为'bottle.py'的单个文件.所以这些都不起作用......
import bottle
from google.appengine.ext.webapp import util
@route('/')
def index():
return "Hello World!"
util.run_wsgi_app(bottle.default_app())
Run Code Online (Sandbox Code Playgroud)
要么
from bottle import *
from google.appengine.ext.webapp import util
@route('/')
def index():
return "Hello World!"
util.run_wsgi_app(bottle.default_app())
Run Code Online (Sandbox Code Playgroud)
我得到的错误信息是......
Traceback(最近一次调用最后一次):
文件"/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py",第3180行,在_HandleRequest self中._Dispatch(dispatcher,self.rfile,outfile,env_dict)文件"/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py",line 3123,在_Dispatch base_env_dict = env_dict)文件"/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py",第515行,在Dispatch base_env_dict中= base_env_dict)文件"/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py",第2382行,在Dispatch self._module_dict中)文件" /应用/ GoogleAppEngi neLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py",第2292行,在ExecuteCGI中reset_modules = exec_script(handler_path,cgi_path,hook)文件"/ Applications /GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py",第2188行,在script_module中的ExecuteOrImportScript exec module_code中.dict 文件"/Users/tyler/Dropbox/sites/dietgrid/code2.py",第4行,在@route('/')NameError:名称'route'未定义
所以我认为它应该能够以其他方式工作或者不工作是错误的吗?
这可能非常简单.但我正在使用WTForms,并希望将字段的值设置为我从数据库中提取的变量.但它不是显示动态变量,而是显示变量名称.
{{ form.question.label }}
{{ form.question(value="{{ q.question }}") }}
{{ form.slug.label }}
{{ form.slug(value="{{ q.slug }}") }}
Run Code Online (Sandbox Code Playgroud)
所以在现场它说"{{q.question}}"而不是"生命的意义是什么?"之类的东西.
有没有办法在Jinja中显示嵌套变量?或者我还有其他方法可以解决这个问题吗?任何帮助表示赞赏!
我有两个型号:
class User(ndb.Model):
email = ndb.StringProperty(required=True)
name = ndb.StringProperty(required=True)
class Post(ndb.Model):
created = ndb.DateTimeProperty(auto_now_add=True)
message = ndb.TextProperty(required=True)
user = ndb.KeyProperty(kind=User)
Run Code Online (Sandbox Code Playgroud)
如果我想循环Post模型中的一些帖子.我如何访问用户模型中的"名称"字段?例如:
for post in posts:
print post.message
print post.user.name
Run Code Online (Sandbox Code Playgroud)
所以我猜测最后一行不正确.我试着搜索,但无法理解.并补充说.有没有办法在Jinja2模板中访问该信息?
最后,我是不是错了?假设有50个帖子.我有1个查询来获得这50个帖子.访问用户模型上的"名称"字段是否会在每次循环时成为附加查询?那51个查询?如果是这样,最好不使用KeyProperty并且只在每个帖子中存储用户数据(即使我有更多数据,如avatar,user_id等)?