【问题标题】:How can I fix this attribute error?如何修复此属性错误?
【发布时间】:2014-05-13 15:40:52
【问题描述】:

我正在处理 web2py HTML 视图,但不断出现错误。 这是代码:

{{extend 'layout.html'}}
<h2>Edit your post</h2>
<h3>for category {{=form.record.category.name.title()}}</h3>
{{=form}}

和错误:

AttributeError: 'NoneType' object has no attribute 'name'

我该如何解决这个错误?

N/B 控制器:

def edit_post():
    id = post.id
    form = SQLFORM(= A("Edit post",_href=URL(request.args=auth.user.id/login))
    return locals()

【问题讨论】:

  • 您的form.record.category 正在返回None 尝试找出原因。
  • 您的代码中还有一个额外的'。

标签: python python-2.7 web2py


【解决方案1】:

请参阅SQLFORM documentation,了解如何创建表单。我假设您在将代码发布到此处之前已经更改了代码,因为由于SQLFORM 的参数列表中的=,python 不会编译它。

【讨论】:

    猜你喜欢
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-22
    相关资源
    最近更新 更多