On Tue 21 Aug 2007, Andreas Stuhlmüller wrote: > Hey Django developers, > > this is the last status update for my Summer of Code project [1] > before (or while) the final evaluation takes place. After a few words > on last week's changes, I would like to summarize what is currently > possible using the REST interface, what is still left to do and why > the REST interface needs your help.
Hi Andreas I cant find a dedicated mailing list for django-rest-interface so I am posting here for the time being. I am not quite sure if I am doing something wrong or not, but I can happily GET and DELETE objects but I am having trouble getting PUT and POST to work, and your examples don't really go into details about how and where the REST client should PUT/POST too.. I have the following (simplified) model: class Device(models.Model): MacAddress = models.CharField(primary_key=True, maxlength=12) SerialNo = models.CharField(maxlength=20) def __str__(self): return str(self.MacAddress) def save(self): super(Device, self).save() # Call the "real" save() method. syslog.syslog('Saving data for: ' + self.MacAddress) def delete(self): syslog.syslog('Deleting: ' + self.MacAddress) super(Device, self).delete() # Call the "real" delete() method. def post(self): syslog.syslog('Updating: ' + self.MacAddress) super(Device, self).post() # Call the "real" post() method. def put(self): syslog.syslog('Adding: ' + self.MacAddress) super(Device, self).put() # Call the "real" delete() method. In urls.py I have: device_resource = Collection( queryset = Device.objects.all(), permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'), receiver = XMLReceiver(), responder = XMLResponder(paginate_by = 10) ) urlpatterns = patterns('', (r'^xml/device/(.*?)/?$', device_resource), ) I have written a simple client using "restclient". You can see it works here for GET and DELETE: # ./atclient -g 000000000001 Processing MAC: 000000000001 <?xml version="1.0" encoding="utf-8"?> <django-objects version="1.0"><object pk="000000000001" model="provisioning.device"><field type="CharField" name="SerialNo">000000000001</field></object></django-objects> # ./atclient -d 000000000001 Deleting MAC: 000000000001 Object successfully deleted. However trying to PUT a new object fails.. # ./atclient -a 000000000001 Adding MAC: 000000000001 <?xml version="1.0" encoding="utf-8"?> <django-error><error-message>404 NOT FOUND</error-message><status-code>404</status-code></django-error> I see the PUT arriving at the web server: [10/Sep/2007 15:03:50] "PUT /xml/device/ HTTP/1.1" 404 142 What exactly should I PUT, and to what url to make it add an object into the database? My client code currently looks like: #! /usr/bin/python import sys import getopt from restclient import GET, POST, PUT, DELETE urlBase = 'http://127.0.0.1:8000/xml/device/' def GetMac(macId): response = GET(urlBase + macId.lower() + '/') print response def DelMac(macId): response = DELETE(urlBase + macId.lower() + '/', async=False) print response def PostMac(macId): response = POST(urlBase + macId.lower() + '/', async=False) print response def AirTiesPutMac(macId): response = PUT(urlBase, async=False) print response if __name__ == '__main__': def print_usage(): usage = "Usage: atclient -g MacAddress" print usage; sys.exit() try: opts, args = getopt.getopt(sys.argv[1:], 'a:d:g:u:') except getopt.GetoptError: print_usage() opts = dict(opts) try: mode = opts.keys()[0] except IndexError: print_usage() if mode == '-g': print "Getting MAC: " + opts['-g'] GetMac(opts['-g']) elif mode == '-d': print "Deleting MAC: " + opts['-d'] DelMac(opts['-d']) elif mode == '-a': print "Adding MAC: " + opts['-a'] PutMac(opts['-a']) elif mode == '-u': print "Updating MAC: " + opts['-u'] PostMac(opts['-u']) I would appreciate any help you can give. Thanks in Advance -- Peter Nixon http://peternixon.net/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---