TCS Wings 1 T4 Django - Set 2

 

  1. You need to implement JWT token-based authentication for an API where the token should expire after 1 hour. Which setting should you modify?
    a) ACCESS_TOKEN_LIFETIME in the Simple JWT configuration
    b) JWT_SECRET_KEY
    c) REFRESH_TOKEN_LIFETIME
    d) SESSION_EXPIRATION_TIME

Answer: a) ACCESS_TOKEN_LIFETIME in the Simple JWT configuration


  1. In your Django application, a Book model has a foreign key to an Author model. How do you fetch all books written by a particular author using Django ORM?
    a) Book.objects.get(author=author)
    b) Book.objects.filter(author=author)
    c) Author.objects.filter(book__title=title)
    d) Book.objects.filter(author__name=author)

Answer: b) Book.objects.filter(author=author)


  1. In Django Rest Framework, you need to handle a POST request to create a new Order. How do you handle the validation of the request data before saving it to the database?
    a) Use form_valid() method
    b) Override the create() method in the serializer
    c) Use a SerializerMethodField in the serializer
    d) Use a ManyToManyField in the model

Answer: b) Override the create() method in the serializer


  1. You are developing a Django application that needs to send emails to users when they register. What Django feature would you use to configure and send these emails?
    a) Django Middleware
    b) EmailMessage class from django.core.mail
    c) Django Sessions
    d) Django Caching

Answer: b) EmailMessage class from django.core.mail


  1. You are working on a Django Rest Framework API that lists a large dataset. To reduce the load on the database, you decide to use query optimization. Which of the following methods would improve performance by reducing the number of database queries?
    a) Use filter()
    b) Use select_related()
    c) Use count()
    d) Use order_by()

Answer: b) Use select_related()


  1. Your Django model contains sensitive user data, and you need to restrict access based on user roles. What is the best way to enforce role-based permissions in Django Rest Framework?
    a) Use IsAuthenticated permission
    b) Use custom permissions in DRF
    c) Define user roles in the urls.py file
    d) Implement @admin_required decorator

Answer: b) Use custom permissions in DRF


  1. You are building a Django application that allows users to reset their passwords. Which built-in Django view would you use to handle the password reset process?
    a) PasswordChangeView
    b) PasswordResetConfirmView
    c) PasswordResetView
    d) ResetView

Answer: c) PasswordResetView


  1. In a Django Rest Framework project, you need to create a serializer that includes a nested relationship between models. What field type should you use to handle nested objects in the serializer?
    a) PrimaryKeyRelatedField
    b) ManyToManyField
    c) SerializerMethodField
    d) NestedSerializer

Answer: a) PrimaryKeyRelatedField


  1. You are creating a Django model for a product catalog, and some products are only available in specific countries. How do you define a field that allows the selection of multiple countries for a product?
    a) Use a ForeignKey field
    b) Use a CharField with choices
    c) Use a ManyToManyField to a Country model
    d) Use a OneToOneField with a Country model

Answer: c) Use a ManyToManyField to a Country model


  1. In Django, you need to apply a function to every HTTP request and response in your application for logging purposes. Which feature would you use to implement this globally?
    a) Django Middleware
    b) Django Views
    c) Django Forms
    d) Django URLs

Answer: a) Django Middleware

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