小编Amr*_* E.的帖子

Python是否具有toString()等价物,我可以将db.Model元素转换为String吗?

我正在编写一个ToDo列表应用程序,以帮助自己开始使用Python.该应用程序在GAE上运行,我将待办事项存储在数据存储中.我想向他们展示每个人的项目,而且他们一个人.问题是该应用程序当前向所有用户显示所有项目,因此我可以看到您所写的内容,并且您可以看到我写的内容.我想把我的todo.author对象转换成一个字符串,看看它是否与用户名相匹配将是一个好的开始,但我无法弄清楚如何做到这一点.

这就是我在main.py中的内容

... 
user = users.get_current_user()

if user:
    nickname = user.nickname()
    todos = Todo.all()
    template_values = {'nickname':nickname, 'todos':todos}
...

def post(self):

    todo = Todo()
    todo.author = users.get_current_user()
    todo.item = self.request.get("item")
    todo.completed = False

    todo.put()      
    self.redirect('/')
Run Code Online (Sandbox Code Playgroud)

在我的index.html中我最初有这个:

<input type="text" name="item" class="form-prop" placeholder="What needs to be done?" required/>
...
 <ul>
{% for todo in todos %}
  <input type="checkbox"> {{todo.item}} <hr />
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)

但我想只向创建它们的用户显示项目.我想过尝试

{% for todo in todos %}
    {% ifequal todo.author nickname %}
  <input type="checkbox"> {{todo.item}} <hr /> …
Run Code Online (Sandbox Code Playgroud)

python google-app-engine django-templates

45
推荐指数
3
解决办法
8万
查看次数

尝试从JSON文件填充JQuery中的列表.怎么调试?

所以我有一个JSON文件,我需要从中获取测验问题.现在,我只是将问题存储在数组中作为对象.每个问题对象都有"文本"(问题本身),"选择"(可能的答案数组)和"答案"(对应于正确答案选择位置的int).

如何检查我是否正确存储了问题对象?我想创建一个问题列表,我尝试使用问题[i] .text填充我的列表,但它不起作用.我安装了Firebug来调试发生了什么,但我不完全确定如何充分利用它.

JSON采用以下格式:

{
"text": "What does the author least like about Eclipse?", 
"choices": [
    "The plugin architecture.",
    "FindBugs.",
    "Refactoring.",
    "The Run As menu."],
"answer": 3
}
Run Code Online (Sandbox Code Playgroud)

我的JavaScript文件:

$(document).ready(function(){

var questions=[];
$.getJSON('quiz.js',function(data){

     var i=0;
     for(i=0;i<data.length;i++){
        questions[i]=[String(data[i].text),String(data[i].choices),int(data[i].answer)];

    }

    var list = $('#list')
    $(questions).each(function(_, text) {
    var item = $('<li/>')
    var link = $('<a/>').html(text)
    link.click(function() { alert(text) })
    item.append(link)
    list.append(item)
    })

    $('#list').listview('refresh')


});
})
Run Code Online (Sandbox Code Playgroud)

最后,一些HTML:

 <div data-role="content">
    <ul id="list" data-role="listview">
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

我知道这是一个很长的问题,但我非常感谢任何帮助.最终目标是提供一个问题列表,单击这些问题时,会显示答案选项并提供一个Toast,以通知用户所选选项是否正确.如果回答正确,我还想在绿色列表中突出显示问题,否则为红色.

编辑:

工作代码:

$(document).ready(function(){

$.getJSON('quiz.js',function(data){

var questions = data; …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery firebug json

6
推荐指数
1
解决办法
1万
查看次数

docker中pg_dump错误但仍然执行成功

我已经容器化了一个 python 脚本,该脚本旨在pg_dump在数据库上运行并将生成的文件上传到服务器。我遇到的问题是我 could not find a "pg_dump" to execute在终端中看到了该消息,但无论如何它似乎都运行成功。例如,如果我运行下面的代码,我会得到输出:

could not find a "pg_dump" to execute
pg_dump (PostgreSQL) 11.10
Run Code Online (Sandbox Code Playgroud)

我想弄清楚为什么这条消息打印在我的终端上,以及它是否表明了我没有看到的更大问题。我仍然清楚地得到我的输出,如上所示,所以我对这条消息的含义感到非常困惑。

Dockerfile:

FROM postgres:11.10-alpine

LABEL maintainer="Foo"

COPY *.py /

ADD requirements.txt /

RUN apk add postgresql-client

# Install python 3
RUN apk add --no-cache python3 \
  && python3 -m ensurepip \
  && pip3 install --upgrade pip setuptools \
  && rm -r /usr/lib/python*/ensurepip && \
  if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi …
Run Code Online (Sandbox Code Playgroud)

python postgresql pg-dump python-3.x docker

1
推荐指数
1
解决办法
1241
查看次数