【发布时间】:2016-11-25 07:53:26
【问题描述】:
我遇到了一个大问题。我有以下表格
db.define_table('post',
Field('user_email', default=auth.user.email if auth.user_id else None),
Field('title', 'string', requires=IS_NOT_EMPTY()),
Field('body', 'text', requires=IS_NOT_EMPTY()),
Field('votes', 'integer', default=0, readable=False, writable=False),
auth.signature
)
db.define_table('comm',
Field('post','reference post'),
Field('body','text'),
auth.signature
)
所以基本上用户可以在登录后创建帖子。我想在帖子上添加添加 cmets 的功能,而无需重新加载整个页面。在这种情况下,我认为我必须使用 ajax 函数。
我不太了解“参考”的工作方式。我认为当我插入新文本时,我必须指定来自哪个帖子,但正如我所说,我很困惑。您能否简要说明如何关联这两个表?因为我必须编写一个 python 函数,我必须在其中指定要在特定帖子上显示的 cmets。
<div class="well">
<h1>{{=post.title}}</h1>
{{=post.body}}
</div>
{{if field_var_created_by == auth.user_id:}}
<a href={{=URL('edit_post',args=post.id)}} class="btn btn-danger" role="button">Edit Post</a>
{{pass}}
<form>
<div class="form-group">
<label for="comment">Comment:</label>
<textarea class="form-control" rows="5" id="comment"></textarea>
<script>
document.write('hello');
</script>
</div>
</form>
<a href="" class="btn btn-success" role="button">Add Comments</a>
如您所见,我使用控制器中的 python 函数检索了视图上帖子的所有数据。我想获取文本区域的输入,将其放入数据库中,然后以某种方式将其显示在此帖子上。
https://wwu39.pythonanywhere.com/prostudy
我的网站在 pythonanywhere 上启动。我遇到的问题在论坛页面中。要访问论坛,您必须登录。别担心,我不会向您发送垃圾邮件。这是一个没有人会使用的小应用程序。去论坛,选择一个帖子,你会看到问题。添加评论按钮还没有做任何事情。我已禁用用户身份验证功能,以方便您使用
【问题讨论】:
标签: javascript python ajax web-deployment web2py