我想用python Bottle框架为api创建一个示例应用程序,我还想在apache服务器上部署这个应用程序,我使用以下示例代码
from bottle import route, run, template
@route('/hello/:name')
def index(name='World'):
return template('<b>Hello {{name}}</b>!', name=name)
@route('/events/:id', method='GET')
def get_event(id):
return dict(name = 'Event ' + str(id))
run(host='localhost', port=8082)
通过使用上述代码,我可以如何创建示例应用程序以及如何在服务器上部署该示例应用程序。如何才能做到这一点?
尝试使用“method=GET/POST/PUT/DELETE”
配方-api.py
配置.json
@phihag,阅读米格尔·格林伯格的这些文章,@miguelgrinberg~http://blog.miguelgrinberg.com/category/REST
从这篇文章开始,“Designing a RESTful API with Python and Flask”~如果需要安装烧瓶,请完成这些步骤。
然后用瓶子重新写申请表。瓶子是一个简单的框架使用,是如此接近烧瓶,我重新编写的代码阅读通过瓶子的例子。有更多的detailed tutorial你可以看一看,一旦你有了基本知识。
值得努力。
下面您将解释如何使用WSGI在apache中部署bottle应用程序:http://bottlepy.org/docs/dev/deployment.html#apache-mod-wsgi
就应用程序而言,您需要最佳的REST兼容,因此了解REST和bottle,这里有一个很好的教程,我使用了:http://myadventuresincoding.wordpress.com/2011/01/02/creating-a-rest-api-in-python-using-bottle-and-mongodb/
相关问题 更多 >
编程相关推荐