TCS Wings 1 T4 Django - Set 7



  1. You are developing an API in Django Rest Framework where you want to return paginated results for a list of items. How can you add pagination globally to your API views?
    a) Set PAGINATE_BY in the view
    b) Add pagination settings in settings.py
    c) Use PageNumberPagination in each view
    d) Define a custom pagination class

Answer: b) Add pagination settings in settings.py


  1. You want to query the last 10 records of a model in Django ORM, sorted by creation date. Which method would you use?
    a) Model.objects.filter().limit(10)
    b) Model.objects.all()[:10]
    c) Model.objects.order_by('-created_at')[:10]
    d) Model.objects.last(10)

Answer: c) Model.objects.order_by('-created_at')[:10]


  1. In your Django project, you want to implement caching for API responses to improve performance. Which middleware should you use to add caching?
    a) SessionMiddleware
    b) CacheMiddleware
    c) SecurityMiddleware
    d) CorsMiddleware

Answer: b) CacheMiddleware


  1. In Django ORM, how do you retrieve only distinct values from a queryset to eliminate duplicates?
    a) Model.objects.unique()
    b) Model.objects.exclude()
    c) Model.objects.distinct()
    d) Model.objects.filter()

Answer: c) Model.objects.distinct()


  1. You are building a REST API with Django Rest Framework and want to use token-based authentication. Which authentication class should you use?
    a) BasicAuthentication
    b) TokenAuthentication
    c) SessionAuthentication
    d) OAuth2Authentication

Answer: b) TokenAuthentication


  1. You want to filter a queryset in Django ORM based on multiple conditions that must all be true. How do you accomplish this?
    a) Use filter() with Q() objects
    b) Use exclude()
    c) Use annotate()
    d) Use all()

Answer: a) Use filter() with Q() objects


  1. You are building a Django Rest Framework API where users can upload images. How do you specify a maximum file size for the uploaded images?
    a) Use MaxValueValidator on the model
    b) Define a custom validator in the serializer
    c) Limit the file size in views.py
    d) Use ImageField() with max_length

Answer: b) Define a custom validator in the serializer


  1. Your Django application needs to handle form submissions via AJAX. Which HTTP method will you primarily use to submit the data from the client-side?
    a) GET
    b) POST
    c) PUT
    d) PATCH

Answer: b) POST


  1. In your Django ORM query, you want to retrieve records where a foreign key field is null. How would you filter this queryset?
    a) filter(foreign_key__isnull=False)
    b) filter(foreign_key__isnull=True)
    c) exclude(foreign_key__isnull=True)
    d) filter(foreign_key=None)

Answer: b) filter(foreign_key__isnull=True)


  1. You want to secure your Django Rest Framework API by allowing only HTTPS connections. Which setting should you modify?
    a) USE_HTTPS
    b) SECURE_SSL_REDIRECT
    c) ALLOW_HTTPS_ONLY
    d) CSRF_USE_SSL

Answer: b) SECURE_SSL_REDIRECT

Comments

Popular posts from this blog

TCS Wings 1 T4 Django - Set 1

TCS Wings 1 T4 Django - Set 10

TCS Wings 1 T4 Django - Set 4