基于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第三方库


热门话题
未检测到“空格”的java ASCII码   音频如何在Java中设置SourceDataLine的音量   java MyBatissSpringBoot无法使用作为bean注入的数据源   Java字谜递归列表<List<String>>仅存储空列表<Strings>   java显示30px高的JPanel,然后用minecraft填充剩余空间   java JOGL平滑度   Java:按完整与否对1d对象数组进行排序   arraylist仅当java结构不存在时才将对象添加到java结构中   无法初始化java渲染库在安卓 studio 4.1.1上出现错误   java SpringBoot ClassCastException   java解析文本文件,基于字数   java=运算符引发异常   java使点可拖动并存储新坐标JavaFx   JavaWebSphereApplicationServer:EJB模块和JMS路由器