变形映射序列不更新
deform Sequence of Mapping not updating
我创建了一个视图,它输出一个包含以下内容的表单:
class Person(colander.Schema):
name = colander.SchemaNode(colander.String())
age = colander.SchemaNode(colander.Integer(),
validator=colander.Range(0, 200))
class People(colander.SequenceSchema):
person = Person()
class Schema(colander.Schema):
people = People()
class SchemaSpace(colander.MappingSchema):
schema = Schema()
corners = colander.SchemaNode(colander.String())
输出是正确的,但是当我点击按钮 Add Person
时,没有任何反应。页面闪烁并向上滚动,什么也没有,我填写任何内容。你知道这里发生了什么吗?我正在使用多个表格,它来自这里吗?
我的HTML很小,我用的是jinja2:
{% extends "layout.jinja2" %}
{% block head %}
<script src="{{request.static_url('deform:static/scripts/jquery-2.0.3.min.js')}}"
type="text/javascript"></script>
<script src="{{request.static_url('deform:static/scripts/bootstrap.min.js')}}"
type="text/javascript"></script>
<script src="{{request.static_url('deform:static/scripts/jquery.form-3.09.js')}}"
type="text/javascript"></script>
<script src="{{request.static_url('deform:static/scripts/jquery-sortable.js')}}"
type="text/javascript"></script>
<script src="{{request.static_url('deform:static/scripts/jquery.maskedinput-1.3.1.min.js')}}"
type="text/javascript"></script>
{% endblock head %}
{% block content %}
<div class="row">
<div class="col-md-8">
<div class="content">
<h1>{{view.view_name}} - {{page_title}}</h1>
<p>Welcome</p>
{{form | safe}}
</div>
</div>
<div class="col-md-4">
<h2>Extra</h2>
<p>some text</p>
</div>
</div>
{% endblock content %}
根据我从文档中找到的内容,我添加了一些脚本。但是我遇到了一些问题,所以我手动输入了它们。使用:
<tal:block tal:repeat="reqt view.reqts['css']">
<link rel="stylesheet" type="text/css"
href="${request.static_url(reqt)}"/>
</tal:block>
问题是:
<script type="text/javascript" src="{{request.static_url(reqt)}}"></script>
File "/Users/roy/Applications/miniconda3/envs/WebAppBatman/lib/python3.6/site-packages/pyramid/url.py", line 644, in static_url
if not os.path.isabs(path):
File "/Users/roy/Applications/miniconda3/envs/WebAppBatman/lib/python3.6/posixpath.py", line 64, in isabs
s = os.fspath(s)
TypeError: expected str, bytes or os.PathLike object, not Undefined
为了完整起见,这里是视图:
@view_config(renderer='templates/settings.jinja2')
def settings(self):
html = []
if 'submit' in self.request.POST:
posted_formid = self.request.POST['__formid__']
for (formid, form) in forms.items():
if formid == posted_formid:
try:
controls = self.request.POST.items()
form['captured'] = form['form'].validate(controls)
html.append(form['form'].render(form['captured']))
except deform.ValidationFailure as e:
# the submitted values could not be validated
html.append(e.render())
else:
if form['captured'] is not None:
html.append(form['form'].render(form['captured']))
else:
html.append(form['form'].render())
else:
for _, form in forms.items():
html.append(form['form'].render())
reqts = forms['form1']['form'].get_widget_resources()
html = ''.join(html)
# values passed to template for rendering
return {'form': html, 'page_title': 'Settings', 'reqts': reqts}
我成功了!这是由于我怀疑的脚本。
这是使用 jinja2:
的工作语法
{% for reqt in reqts['js'] %}
<script src="{{request.static_url(reqt)}}"
type="text/javascript"></script>
{% endfor %}
我无法使用 tap:repeat
使其工作。
我创建了一个视图,它输出一个包含以下内容的表单:
class Person(colander.Schema):
name = colander.SchemaNode(colander.String())
age = colander.SchemaNode(colander.Integer(),
validator=colander.Range(0, 200))
class People(colander.SequenceSchema):
person = Person()
class Schema(colander.Schema):
people = People()
class SchemaSpace(colander.MappingSchema):
schema = Schema()
corners = colander.SchemaNode(colander.String())
输出是正确的,但是当我点击按钮 Add Person
时,没有任何反应。页面闪烁并向上滚动,什么也没有,我填写任何内容。你知道这里发生了什么吗?我正在使用多个表格,它来自这里吗?
我的HTML很小,我用的是jinja2:
{% extends "layout.jinja2" %}
{% block head %}
<script src="{{request.static_url('deform:static/scripts/jquery-2.0.3.min.js')}}"
type="text/javascript"></script>
<script src="{{request.static_url('deform:static/scripts/bootstrap.min.js')}}"
type="text/javascript"></script>
<script src="{{request.static_url('deform:static/scripts/jquery.form-3.09.js')}}"
type="text/javascript"></script>
<script src="{{request.static_url('deform:static/scripts/jquery-sortable.js')}}"
type="text/javascript"></script>
<script src="{{request.static_url('deform:static/scripts/jquery.maskedinput-1.3.1.min.js')}}"
type="text/javascript"></script>
{% endblock head %}
{% block content %}
<div class="row">
<div class="col-md-8">
<div class="content">
<h1>{{view.view_name}} - {{page_title}}</h1>
<p>Welcome</p>
{{form | safe}}
</div>
</div>
<div class="col-md-4">
<h2>Extra</h2>
<p>some text</p>
</div>
</div>
{% endblock content %}
根据我从文档中找到的内容,我添加了一些脚本。但是我遇到了一些问题,所以我手动输入了它们。使用:
<tal:block tal:repeat="reqt view.reqts['css']">
<link rel="stylesheet" type="text/css"
href="${request.static_url(reqt)}"/>
</tal:block>
问题是:
<script type="text/javascript" src="{{request.static_url(reqt)}}"></script>
File "/Users/roy/Applications/miniconda3/envs/WebAppBatman/lib/python3.6/site-packages/pyramid/url.py", line 644, in static_url
if not os.path.isabs(path):
File "/Users/roy/Applications/miniconda3/envs/WebAppBatman/lib/python3.6/posixpath.py", line 64, in isabs
s = os.fspath(s)
TypeError: expected str, bytes or os.PathLike object, not Undefined
为了完整起见,这里是视图:
@view_config(renderer='templates/settings.jinja2')
def settings(self):
html = []
if 'submit' in self.request.POST:
posted_formid = self.request.POST['__formid__']
for (formid, form) in forms.items():
if formid == posted_formid:
try:
controls = self.request.POST.items()
form['captured'] = form['form'].validate(controls)
html.append(form['form'].render(form['captured']))
except deform.ValidationFailure as e:
# the submitted values could not be validated
html.append(e.render())
else:
if form['captured'] is not None:
html.append(form['form'].render(form['captured']))
else:
html.append(form['form'].render())
else:
for _, form in forms.items():
html.append(form['form'].render())
reqts = forms['form1']['form'].get_widget_resources()
html = ''.join(html)
# values passed to template for rendering
return {'form': html, 'page_title': 'Settings', 'reqts': reqts}
我成功了!这是由于我怀疑的脚本。 这是使用 jinja2:
的工作语法{% for reqt in reqts['js'] %}
<script src="{{request.static_url(reqt)}}"
type="text/javascript"></script>
{% endfor %}
我无法使用 tap:repeat
使其工作。