通过googleappengine中的get发送multivar字典;python

2024-06-07 11:33:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近开始在谷歌应用程序引擎上工作,面临以下问题:

我有一个主.py我的用户看到他自己的评论+其他人的评论。现在,我需要添加一个编辑评论.py当一个用户想要编辑他的代码时,他被引导到哪里。你知道吗

我只使用留言簿应用程序,要实际获取所选的评论,我需要留言簿名称和评论内容。如何创建此url?你知道吗

换句话说,我需要创建一个类似

 \edit?guestbook="Family"&content="helloworld"

我试过了

//I need to send guestbook_name and content of greeting in order to fetch the row from
//the database
//So, I show the text of the greeting and give a url to edit page 

content_toSend = {'guestbook_name':guestbook_name,'content':greeting.content}

self.response.write('<blockquote><a href="/edit?%s">%s</a></blockquote>' %
                            (content_toSend,greeting.content))

//But the other side handler receives only the first variable of the dict in the get request

这样用户就可以点击一个问候语并被引导到编辑页面。但是get请求只发送url中的第一个var(guestbook\u名称)。我怎么把整本字典寄出去?你知道吗

编辑:我累了urllib.urlencode文件但是webapp2中的处理程序需要dict,所以这不起作用


Tags: oftheto用户namepy应用程序url
2条回答

urllib标准库的方法^{}可能很有用。你知道吗

编辑示例:

content_toSend = urllib.urlencode({
    'guestbook_name' : guestbook_name,
    'content' : greeting.content
    })

如果你知道字典里会有这两个变量,为什么不试试这个呢

self.response.write('<blockquote><a href="/edit?guestbook=%s&content=%s">%s</a></blockquote>' %
                        (content_toSend['guestbook_name'],content_toSend['content'],greeting.content))

相关问题 更多 >

    热门问题