web.py 下, get 和 post 同传入参数,导致错误,请问怎么解决?代码已贴

2015-05-18 23:43:54 +08:00
 redhatping
go.py

```python
import web

urls = ('/','Index')
render = web.template.render('templates/')
db= web.database( dbn='sqlite',db='movesite.db')


class Index(object):
def GET(self):
return render.index(self)


def POST(self):
data=web.input()
inputtext = r'name like"%' + data.title + r'%"'
print inputtext
move = db.select('move',where =inputtext)
return render.index(move)

if __name__ == '__main__':

app = web.application(urls,globals())
app.run()

```
index.html
如下:
```html
$def with (movies)
<html>
<head>
<meta charset="UTF-8">
<title>hello world</title>
</head>
<body>

<h1>豆瓣movies</h1>

<form action = "/" method = "post">
<input type ='text' name = 'title' />
<input type='submit' value ='搜索'/>
</form>

$for move in movies:
<li>$move.name
</li>


</body>
</html>

```

只要我去搜索了,系统就会错误,原因就是get,post冲突的, 可解决办法是post ,action去其他目录,但是我就要这个目录实现怎么办呢?

2, 另外一个
move = db.select('move',where =inputtext)

type(move) ,发现是一个类实例, 但是类实例, 也可以迭代吗? 。
2904 次点击
所在节点    Python
8 条回复
est
2015-05-18 23:59:11 +08:00
redhatping
2015-05-19 00:02:06 +08:00
提问没什么丢人的, 可以百度的,当然迅速百度的, 还去微博@, 这不就是互联网,不如说我 爬书学习速度不错。。

读书笔记这里:[python笔记](http://www.jianshu.com/notebooks/925220/latest)
awanabe
2015-05-19 00:12:33 +08:00
@est
楼主 在5天前的帖子里面回复... 会注意贴代码用markdown ...
然后还是这样一坨代码...
zhicheng
2015-05-19 00:19:31 +08:00
1,完全不知道你在说什么。你确定你说的 GET 和 POST 冲突?这俩东西怎么个冲突法啊,我想知道。
2,为什么类实例不能迭代,这是 1 + 1 = 2 的问题。
lidashuang
2015-05-19 00:23:56 +08:00
这种代码不格式化一下就是懒
redhatping
2015-05-19 00:32:57 +08:00
@awanabe 我已经尝试了 ```python ```, 似乎这种markdown失效了, 我会检查一下下次
redhatping
2015-05-19 00:34:25 +08:00
@zhicheng
好的,

贴主要代码一下:

def get(self):
return render.index ( 参数) ,没有参数不行,语法会报错。

deg post(self):
redhatping
2015-05-19 00:38:43 +08:00
def post(self):
return.index(参数)

在index,html中, 因为要读取参数中传递过来的值,$def with (name), 因为name 不知道 是对应get,post 参数的, 如果读取get的参数, 而index.html代码,对于参数进行迭代,就发现这个参数与哦问题。

谢谢了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/192058

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX