Multiple lookup_fields for django rest framework

Try this from django.db.models import Q import operator from functools import reduce from django.shortcuts import get_object_or_404 class MultipleFieldLookupMixin(object): def get_object(self): queryset = self.get_queryset() # Get the base queryset queryset = self.filter_queryset(queryset) # Apply any filter backends filter = {} for field in self.lookup_fields: filter[field] = self.kwargs[field] q = reduce(operator.or_, (Q(x) for x in filter.items())) return … Read more

WCF DataContract DataMember order?

decorate it with the Order Parameter in the DataMemberAttribute class: [DataMember(Order = index)] The reflector in the serializer puts it alphabetically. Unless when decorated like this: [DataMember(Order = 0)] public string FirstName { get; set; } [DataMember(Order = 1)] public string LastName { get; set; } [DataMember(Order = 2)] public string Email { get; set; … Read more

Spring/Rest @PathVariable character encoding

I thing that you need add filter to web.xml <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

SPRING REST: The request was rejected because no multipart boundary was found

The problem isn’t in your code – it’s in your request. You’re missing boundary in your multipart request. As it said in specification: The Content-Type field for multipart entities requires one parameter, “boundary”, which is used to specify the encapsulation boundary. The encapsulation boundary is defined as a line consisting entirely of two hyphen characters … Read more

How do I restrict JSON access?

I think you might be misunderstanding the part where the JSON request is initiated from the user’s browser rather than from your own server. The static HTML page is delivered to the user’s browser, then it turns around and executes the Javascript code on the page. This code opens a new connection back to your … Read more

Reading JSON from SimpleHTTPServer Post data

Thanks matthewatabet for the klein idea. I figured a way to implement it using BaseHTTPHandler. The code below. from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer import SocketServer import simplejson import random class S(BaseHTTPRequestHandler): def _set_headers(self): self.send_response(200) self.send_header(‘Content-type’, ‘text/html’) self.end_headers() def do_GET(self): self._set_headers() f = open(“index.html”, “r”) self.wfile.write(f.read()) def do_HEAD(self): self._set_headers() def do_POST(self): self._set_headers() print “in post method” … Read more

How do I POST an array of objects with $.ajax (jQuery or Zepto)

Be sure to stringify before sending. I leaned on the libraries too much and thought they would encode properly based on the contentType I was posting, but they do not seem to. Works: $.ajax({ url: _saveAllDevicesUrl , type: ‘POST’ , contentType: ‘application/json’ , data: JSON.stringify(postData) //stringify is important , success: _madeSave.bind(this) }); I prefer this … Read more

Avoid duplicate POSTs with REST

Another solution that’s been proposed for this is POST Once Exactly (POE), in which the server generates single-use POST URIs that, when used more than once, will cause the server to return a 405 response. The downsides are that 1) the POE draft was allowed to expire without any further progress on standardization, and thus … Read more