TCS Wings 1 T4 Django - Set 7
- 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) SetPAGINATE_BYin the view
b) Add pagination settings insettings.py
c) UsePageNumberPaginationin each view
d) Define a custom pagination class
Answer: b) Add pagination settings in settings.py
- 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]
- 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
- 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()
- 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
- You want to filter a queryset in Django ORM based on multiple conditions that must all be true. How do you accomplish this?
a) Usefilter()withQ()objects
b) Useexclude()
c) Useannotate()
d) Useall()
Answer: a) Use filter() with Q() objects
- 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) UseMaxValueValidatoron the model
b) Define a custom validator in the serializer
c) Limit the file size inviews.py
d) UseImageField()withmax_length
Answer: b) Define a custom validator in the serializer
- 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
- 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)
- 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
Post a Comment