基于django的rest api框架

rinzler的Python项目详细描述


#rinzler-rest框架





;安装需要


``php
``php
pip install rinzler
```
`
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `使用
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `控制器导入控制器

base廑dir=os.path.dirname(os.path.dirname(os.path.abspath(廑file廑))

assembler=app['url廑assembler']

urlpatterns=[
assembler.mount('hello',controller),
assembler.mount(''',maincontroller),
]

````

```python
app):

router=app['router']

app:dict(),**param s:dict):

默认路由回调
:param request httprequest
:param app rinzler's object
:param params dict url params,如果存在,请尝试:
:rtype:response

尝试:
response=ordereddict()
response[“status”]=true
response[“data”]=“Hello World!”

返回响应(response,content\u type=“application/json”)
基本异常除外,例如e:
response=orderedict()
response[“status”]=false
response[“mensagem”]=str(e)

返回响应(response,content\u type=“application/json”,status=500)\

@staticmethod
def hello_用户(请求:httprequest,app:dict(),**param s:dict):

默认路由回调
:param request httprequest
:param app rinzler的对象
:param params dict url params,如果存在
:rtype:response
”“
”请尝试:
user=params['name]
response=ordereddict()
response[“status”]=true
response[“data”]=“您好{0}!”.format(user)

return response(response,content_type=“application/json”)
除了baseexception,例如e:
response=ordereddict()
response[“status”]=false
response[“mensage”]=str(e)

return response(response,content_type=“application/json”,状态=500)

````
``python manage.py runserver
2017年8月2日-18:48:00
django版本1.10.4,使用设置“demo.settings”
在http://127.0.0.1:8000启动开发服务器/
使用control-c退出服务器。
````

```shell
curl http://localhost:8000/
<;center>;<;h1>;http/1.1200 ok rinzler framework<;/h1>;<;/center>;

curl http://localhost:8000/hello/world/
{
“status”:true,
“data”:“hello world!”
}

{
“status”:true,
“data”:“hello bob!”
}


curl http://localhost:8000/foo/bar/
{
“status”:false,
“exceptions”:{
“message”:“找不到get foo/bar/”
},
“request”:{
“content”:,
“method”:“get”,
“path-info”:“foo/bar/”
“message”:“很抱歉,但是出了严重的问题。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
使用odbc的java数据库连接:找不到microsoft access驱动程序(*.mdb*.accdb)选项   java我在将文本读入数组时遇到问题,我需要在这段代码中更改什么?   java JAXB元素列表中缺少字段   java Android BaseAdapter,返回项id   登录到web应用程序的java语音识别   java线性布局不填充滚动视图中屏幕的剩余部分   java如何通过点击第二个按钮来显示第二张壁纸?   java如果使用无缓冲I/O,缓冲I/O如何减少开销?   《骑士之旅》中的java问题   java如何解决Singelton为空的问题   java可在后台播放广告   在Swing中处理JFXPanel时发生java JavaFX非法状态异常   java Contains总是返回false   java ZeroMQ两个PUBSUB代理