[Fixed]-Return_to_string in DetailView

1👍

I don’t think you’re overriding the get_object() method correctly. Your implementation can return an HttpResponse object which the DetailView doesn’t seem to be able to and display properly. Even if it could serialize the HttpResponse object, your code is trying to display the field/values of the HttpResponse object you’re constructing, when what you really want is for the view to return the HttpResponse object itself. What you want to do is remove all the ajax detection, serialization, and response generation logic in the get_object method and move it into an override of the view’s get() method something to the effect of:

def get(self, request, *arg, **kwargs):
    if request.is_ajax():
       # Generate and return your HttpResponse object here
    return super(ProfileDetails, self).get(request, *args, **kwargs)

The return value of the get method is supposed to be an HttpResponse object which the base View class knows how to handle. I encourage you to review the documentation for class-based views to get a better understanding of how they process requests/responses.

Leave a comment