2

reading This question it looks like I can setup DRF within an existing django project.

That got me thinking... I have a django application that uses ajax calls which return very simple view partials which quickly display on the page, and then a few seconds later another ajax call is made to return another view. (you can think of it like the Whac-a-mole games, but each mole is a different view partial being returned from the server.)

so essentially I have 30-50 calls per minute to mysite.com/ajax_new_mole with a view similar to (just made this up on the fly, ignore any errors)

...
def ajax_new_mole(request):
  random_id = get_random_mole_id()
  random_mole = Mole.objects.get(id = random_id)
  return render(request, 'partials/_mole_photo.html, {'mole':random_mole})
...

and the _mole_photo.html template

{% load load_cloudfront %}
<div class="img-wrapper" id="{{ photo.id }}">
  <span class="album-title" id="album-title">Title: {{ mole.name }}</span>
  <img src='{% load_cloudfront_medium mole.name %}' id="image{{ photo.id }}"/>
</div>

Now to my question. In this situation. Would Django REST Framework offer any performance benefits in the reduced overhead for responding to and rendering this content?

1
  • 3
    DRF is just based on the basic django requests build up with alot more functions easier to handle everything that an API need, so since it's an extension the speed efficiency would be not as fast as normal django request because DRF also use rendering when returning result so i would say it's slower. There an interesting article on testing speed of DRF which is here if you want to check it out. Commented Nov 28, 2019 at 4:46

1 Answer 1

2

The bottleneck of the DRF is in Serializers. So the hardest part is for serializing the model and deserializing the request. That's why if you are using it only for this type of small snippet, then I would not suggest using DRF. You'd better use it only if you have more than 10 API views.

Sign up to request clarification or add additional context in comments.

1 Comment

I have updated @Pynchia, sorry, I have written in a rush and that was the reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.