python - Google App Engine 上的简单博客 - 没有显示任何条目

标签 python google-app-engine

我见过关于同一主题的类似问题,该主题是使用 Python 编写一个非常简单的博客并托管在 GAE 上。如果我错过了其中一个答案中的解决方案,我深表歉意。

我根本看不到任何正在显示的数据库条目。这是我的代码:

实体:

class Comment(db.Model):
    name = db.StringProperty(required=True)
    comment = db.TextProperty(required=True)
    created = time.strftime("%d/%m/%Y")

主处理程序:

class MainPage(Handler):
    def render_front(self, name="", comment="", error=""):
        comments = db.GqlQuery("SELECT * FROM Comment ORDER BY created DESC")
        self.render("front.html", name=name, comment=comment, error=error, comments=comments)
    def get(self):
        self.render_front()
    def post(self):
        name = self.request.get("name")
        comment = self.request.get("comment")
        if name and comment:
            c = Comment(name=name, comment=comment)
            c.put()
            time.sleep(0.5)
            self.redirect("/")

因此这将显示在 HTML 中:

{% for e in comments %}
    <div class="comment">
        <div class="comment-name">
            {{e.name}}
        </div>
        <pre class="comment-content">
            {{e.comment}}
            <br>
            on {{e.created}}
        </pre>
    </div>
{% endfor %}

问题是程序似乎完全忽略了上面的for block 。我设法让它工作了一段时间,但我检查了很多次,看不出问题出在哪里。

任何帮助将不胜感激。提前致谢。

最佳答案

检查此问题的几种方法:

  • 使用管理控制台查看您的数据存储区。里面有记录吗?

  • 您的日期时间属性存储正确吗?有关 DS 和 Datetime 的文档,请参阅此处:https://developers.google.com/appengine/docs/python/datastore/typesandpropertyclasses#DateTimeProperty

  • 您是否已将日期设置为“dateTimeProperty”类型?请参阅此处的示例:developers.google.com/appengine/docs/python/ndb/queries 另请参阅此处:stackoverflow.com/questions/9700579/gql-select-by-date

  • 尝试删除 GQL 中的 ORDER BY 子句。我想知道日期/时间变量是否有什么奇怪的

  • 尝试使用 App Engine SDK 在本地运行,并使用其中的日志来查看行为。当您对一切正常进行感到满意时,您可以将其上传到 GAE。

  • 不要使用模板引擎——现在只需在Python中完全执行循环——然后self.response.write出东西。这将告诉您查询是否正常工作。

希望它对你有用! :)

关于python - Google App Engine 上的简单博客 - 没有显示任何条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20953624/

相关文章:

linux - google-cloud-sdk 安装在 CentOS/usr/local/bin 中找不到正确的 Python 2.7 版本

javascript - GAE 和 JavaScript 日期时间同步

algorithm - 分摊分布(和百分位数)的计算,适用于 App Engine?

python - 比较谷歌应用程序引擎数据存储中的多个日期范围(多对多,Python)

python - 从 IP 地址获取主机名

python - 如何将列中的列表转换为垂直形状?

python - 计算数据帧中特定列(SUM、AVG、STDEV)的所有嵌套级别聚合

python - 计算单词之间的余弦相似度

python - 模式的递归生成

python - 如何在服务器端完全启用 Facebook OAuth 2.0?