[英]Error in using python web.py framework
I am working on python, i want to develop some simple web application which consists of 3 pages(forms) 我正在开发python,我想开发一些简单的Web应用程序,包含3页(表单)
login screen
which should validate username and password and redirect to 2nd page login screen
应该验证用户名和密码并重定向到第二页
If user present it redirects to this page which consists of a list of records and add button
to add another record 如果用户出现,则重定向到此页面,该页面由记录列表组成,并
add button
以添加另一条记录
When clicked on add record
in 2nd page that should redirect to this page which consists of a simple form fields which takes data and saving to 2nd page as a record in a list when clicked on submit
button 当点击第二页中的
add record
时应重定向到此页面,该页面包含一个简单的表单字段,当单击submit
按钮时,该字段将数据保存到第二页作为列表中的记录
I don't want to use high level frameworks like django for the above small requirement so decided to use one of the following frameworks after googgling a lot 我不想在上面的小要求中使用像django这样的高级框架,因此决定在googgling之后使用以下框架之一
Wheezy.web ( https://bitbucket.org/akorn/wheezy.web/downloads ) Wheezy.web( https://bitbucket.org/akorn/wheezy.web/downloads )
web.py ( http://webpy.org/ ) web.py( http://webpy.org/ )
bottle (http://bottlepy.org/docs/dev/) 瓶子(http://bottlepy.org/docs/dev/)
Flask (http://flask.pocoo.org/) Flask(http://flask.pocoo.org/)
I started to use web.py
framework and created a code.py
file as indicated in the tutorial as below 我开始使用
web.py
框架并创建了一个code.py
文件,如下面的教程中所示
code.py code.py
import web
render = web.template.render('templates/')
urls = ( '/', 'index' )
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
After running the above file with python code.py
the result is 用
python code.py
运行上面的文件后,结果是
sh-4.2$ python code.py
http://0.0.0.0:8080/
i have change the ip and port as below 我已经更改了ip和port,如下所示
python code.py 192.168.1.112:2030
and tried to access through a browser , then i recieved the following error 并尝试通过浏览器访问,然后我收到以下错误
<type 'exceptions.KeyError'> at /
u'index'
Python /usr/lib/python2.7/site-packages/web/application.py in _delegate, line 418
Web GET http://0.0.0.0:8080/
Traceback (innermost first)
/usr/lib/python2.7/site-packages/web/application.py in _delegate
cls = fvars[f] ...
▶ Local vars
/usr/lib/python2.7/site-packages/web/application.py in handle
return self._delegate(fn, self.fvars, args) ...
▶ Local vars
/usr/lib/python2.7/site-packages/web/application.py in process
return self.handle() ...
▶ Local vars
Request information
INPUT No data.
COOKIES No data.
...............
Actually when i type the url in to address bar a hello world message should appear as indicated in tutorial, but instead i am getting the above error. 实际上当我在地址栏中键入url时,应该如教程中所示出现hello world消息,但我得到上述错误。
Wheezy.web ( https://bitbucket.org/akorn/wheezy.web/downloads)
framework provided there is no docuemntation showing on how to create a file and start developing Wheezy.web ( https://bitbucket.org/akorn/wheezy.web/downloads)
框架提供没有docuemntation显示如何创建一个文件并开始开发 please help me on the above scenarios 请帮我解决上述情况
The line: 这条线:
urls = ( '/', 'index' )
tells web.py the url /
should be handled by a class index
. 告诉web.py url
/
应该由类index
处理。 You have not created such class and therefore you get the error. 您尚未创建此类,因此您会收到错误。 Fix it like so:
修复它是这样的:
import web
urls = (
'/', 'index'
)
class index:
def GET(self):
return "Hello, world!"
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.