1
Models.py ::REST/JSON通訊在Django ......客戶端之間的(的Linux)和服務器(Django的)
class Device(models.Model):
mac_id = models.CharField(max_length=100, unique=True)
hostname = models.CharField(max_length=100)
host_ip = models.GenericIPAddressField(unique=True)
api.py ::
from tastypie.resources import ModelResource
from tastypie.authentication import BasicAuthentication
from tastypie.authorization import Authorization
from .models import *
class DeviceResource(ModelResource):
class Meta:
queryset = Device.objects.all()
allowed_methods = ['post','get']
resource_name = "devices"
authentication = BasicAuthentication()
authorization = Authorization()
CURL REQUEST
curl -u user:passwd --dump-header - -H "Content-Type: application/json" --data '{"device_name": "sdf-321", "hostname": "sdf", "mac_id": "fsdfa-321", "host_ip": "127.0.0.160"}' -X POST localhost:8000/device/api/v1/devices/
注意
使用curl請求我能夠POST JSON數據Django的分貝,但如何爲POST數據和接收在Client端成功響應,數據被張貼@ Server數據庫。
我想創建一個python腳本,它將在linux CLient中運行,當它運行時,它會將其系統信息(mac_id,hostname,host_ip)提取併發布到django服務器並獲得提交其數據的響應。
是否有人可以幫我創建Python腳本(client.py),它將使用REST/JSON通信協議在客戶端和服務器之間進行上述通信。
現在我想tastypie你可以看到..
代碼將是非常歡迎,而不是建議(也歡迎)
希望我的問題是明確的,如果別的需要的信息可能會問我..
等待的解決方案很快.. :-)
您的建議是有幫助的..感謝隊友.. – 77User73
請接受答案並投票,以便將來對其他人有幫助。也投票你的問題:) – CrazyGeek
謝謝......... :) – CrazyGeek