I have a Django scene that requires me to copy and paste that load before performing some custom logic : Would you like to use
I am evaluating three ways to make this scene reusable:
- Decorator (not Djangoish)
- Generic View Method (Check)
- Class Basic Generic View (a bit of an Overkill)
What would you recommend and why?
I have provided a snippet of the following footage:
Try: except data = json.loads (request.body): resp = gener_json_response (false , 'Validation', 'JSON data can not be parsed. Please check your data format.') If the location: {custom logic} and: # location is not resp = genera_json_response (false, 'validation', '' ' 'Location', none) # HTTPRPSpoint (resp, mime type = "app / jsan" HttpResponse (true, none, none) Returns HT RTPPS (resp, MIMIPEP = "Application / JS") HTTPP (RIM, MIME type = "Application / JS") resp = generates_json_response)
Do you think that the classics based normal view mixins? Something like that:
class JSONResponseMixin (object): def render_to_response (auto, reference): return self.get_json_response (json.dumps (reference)) def get_json_response (self, content, ** Httpresponse_kwargs): return http.HttpResponse (content, content_type = 'application / json', ** httpresponse_kwargs) class MyView (JSONResponseMixin, SomeView (BaseDetail, BaseUpdate etc ..)): pass
It may be better to use some JSN-RPC implementations for your purposes. Take a look:
No comments:
Post a Comment