Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 6 MCQs Cookies and Sessions, users and authentication

INT253 — Web Development In Python Using Django 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Creating Cookies and sessions in Django Easy

    Which method is used to create a cookie in a Django HTTP response?

  2. Question 2 of 60 Creating Cookies and sessions in Django Easy

    Which attribute provides access to cookies received in a Django request?

  3. Question 3 of 60 Creating Cookies and sessions in Django Easy

    Which method removes a cookie from a Django response?

  4. Question 4 of 60 Creating Cookies and sessions in Django Easy

    How is a value normally stored in a Django session?

  5. Question 5 of 60 Creating Cookies and sessions in Django Easy

    Which method removes all data from the current Django session and deletes its session key?

  6. Question 6 of 60 Creating and Managing Users in Django Easy

    Which built-in Django model is commonly used to represent a user?

  7. Question 7 of 60 Creating and Managing Users in Django Easy

    Which manager method creates a regular Django user while correctly processing the password?

  8. Question 8 of 60 Creating and Managing Users in Django Easy

    Which command creates a Django superuser from the command line?

  9. Question 9 of 60 Creating and Managing Users in Django Easy

    Which method should be used to change a user's password securely?

  10. Question 10 of 60 Creating and Managing Users in Django Easy

    Which user attribute indicates whether a Django user can access the admin site?

  11. Question 11 of 60 Login and Logout URLs in Django Easy

    Which URL configuration includes Django's built-in authentication routes?

  12. Question 12 of 60 Login and Logout URLs in Django Easy

    What is the default URL name for Django's built-in login route?

  13. Question 13 of 60 Login and Logout URLs in Django Easy

    What is the default URL name for Django's built-in logout route?

  14. Question 14 of 60 Login and Logout URLs in Django Easy

    Which class-based view provides Django's built-in login behavior?

  15. Question 15 of 60 Login and Logout URLs in Django Easy

    Which class-based view provides Django's built-in logout behavior?

  16. Question 16 of 60 Using Django Login in Views Easy

    Which Django function checks a username and password and returns a user when the credentials are valid?

  17. Question 17 of 60 Using Django Login in Views Easy

    Which function attaches an authenticated user to the current Django session?

  18. Question 18 of 60 Using Django Login in Views Easy

    Which function logs the current user out in a Django view?

  19. Question 19 of 60 Using Django Login in Views Easy

    Which decorator restricts a function-based Django view to authenticated users?

  20. Question 20 of 60 Using Django Login in Views Easy

    Which expression checks whether the current user is authenticated?

  21. Question 21 of 60 Creating Cookies and sessions in Django Medium

    A view must store a visitor's preferred theme in a cookie before returning a response. Which implementation is correct?

  22. Question 22 of 60 Creating Cookies and sessions in Django Medium

    A cookie named language may not exist in every request. Which expression safely returns "en" when the cookie is missing?

  23. Question 23 of 60 Creating Cookies and sessions in Django Medium

    A shopping-cart view needs to store a product ID in the current user's Django session. Which statement should the view use?

  24. Question 24 of 60 Creating Cookies and sessions in Django Medium

    A user selects "Remember me" during login, and the application should keep the session for two weeks. Which call applies this expiry to the current session?

  25. Question 25 of 60 Creating Cookies and sessions in Django Medium

    A logout-related view must remove all session data and invalidate the current session key. Which method is most appropriate?

  26. Question 26 of 60 Creating and Managing Users in Django Medium

    A registration view must create a user while ensuring that the password is securely hashed. Which approach is correct?

  27. Question 27 of 60 Creating and Managing Users in Django Medium

    An administrator has retrieved a user object and wants to replace its password. Which code correctly updates the stored password?

  28. Question 28 of 60 Creating and Managing Users in Django Medium

    A user should be allowed to access the Django administration site but should receive only explicitly assigned permissions. Which flag should normally be enabled?

  29. Question 29 of 60 Creating and Managing Users in Django Medium

    A registration form should validate that two password entries match and should save the password securely. Which built-in form is designed for this task?

  30. Question 30 of 60 Creating and Managing Users in Django Medium

    A user has been assigned the blog.change_post permission. Which expression checks that permission using Django's authorization API?

  31. Question 31 of 60 Login and Logout URLs in Django Medium

    A project wants to use Django's built-in login, logout, and password-management URL patterns under /accounts/. Which project-level URL pattern is appropriate?

  32. Question 32 of 60 Login and Logout URLs in Django Medium

    After including django.contrib.auth.urls under /accounts/, which URL is used by the default named login route?

  33. Question 33 of 60 Login and Logout URLs in Django Medium

    Django's built-in LoginView is used without specifying template_name. Which template path does it look for by default?

  34. Question 34 of 60 Login and Logout URLs in Django Medium

    A project should redirect users to /dashboard/ after login when no next parameter is provided. Which setting should be configured?

  35. Question 35 of 60 Login and Logout URLs in Django Medium

    A template should generate the logout URL without hard-coding its path. Which template tag should be used when Django's authentication URLs are included?

  36. Question 36 of 60 Using Django Login in Views Medium

    A function-based view must be accessible only to authenticated users. Which implementation follows Django's standard approach?

  37. Question 37 of 60 Using Django Login in Views Medium

    A login view has received a username and password. What is the correct sequence for establishing an authenticated session?

  38. Question 38 of 60 Using Django Login in Views Medium

    A view should display a personalized dashboard only when the current request belongs to an authenticated user. Which condition is appropriate?

  39. Question 39 of 60 Using Django Login in Views Medium

    A function-based view should require the inventory.delete_product permission and raise an HTTP 403 response when an authenticated user lacks it. Which decorator is appropriate?

  40. Question 40 of 60 Using Django Login in Views Medium

    A custom logout view needs to remove the authenticated user's identity from the session before redirecting to the home page. Which code performs the logout correctly?

  41. Question 41 of 60 Creating Cookies and sessions in Django Hard

    A view executes response = HttpResponse("OK"), calls response.set_cookie("theme", "dark"), but finally returns a newly created HttpResponse("Done"). What will the client receive?

  42. Question 42 of 60 Creating Cookies and sessions in Django Hard

    A cookie created with response.set_signed_cookie("role", "editor", salt="access") is later modified by the client. What happens when the server calls request.get_signed_cookie("role", salt="access") without a default value?

  43. Question 43 of 60 Creating Cookies and sessions in Django Hard

    A cookie was set with path="/store/" and domain="example.com". A later call to delete_cookie("cart") uses the defaults for both attributes. Why might the browser retain the cookie?

  44. Question 44 of 60 Creating Cookies and sessions in Django Hard

    Given request.session["prefs"] = {"theme": "light"}, a later request executes request.session["prefs"]["theme"] = "dark". Under Django's default save-on-modification behavior, what is required to reliably persist this nested change?

  45. Question 45 of 60 Creating Cookies and sessions in Django Hard

    Which session operation is appropriate after a privilege change when the application must issue a new session key while preserving the current session data?

  46. Question 46 of 60 Creating Cookies and sessions in Django Hard

    A view calls request.session.set_expiry(300). Subsequent requests only read session values and never modify the session. Which expiration behavior should be expected?

  47. Question 47 of 60 Creating and Managing Users in Django Hard

    A developer creates a user with User.objects.create(username="nina", password="secret"). The row exists, but authentication with secret fails. What is the underlying problem?

  48. Question 48 of 60 Creating and Managing Users in Django Hard

    A reusable app needs a foreign key to the project's user model and must support projects that replace Django's default User. Which declaration is appropriate in the model?

  49. Question 49 of 60 Creating and Managing Users in Django Hard

    A custom user manager implements create_superuser() but permits is_staff=False or is_superuser=False when explicitly supplied. What should a robust implementation do?

  50. Question 50 of 60 Creating and Managing Users in Django Hard

    A long-lived User instance has already been checked with has_perm(). Its group permissions are then changed in the database, but another check on the same instance returns the old result. What is the safest correction?

  51. Question 51 of 60 Creating and Managing Users in Django Hard

    A password passes through User.objects.create_user() but violates a validator listed in AUTH_PASSWORD_VALIDATORS. Why can this occur?

  52. Question 52 of 60 Login and Logout URLs in Django Hard

    A project adds path("accounts/", include("django.contrib.auth.urls")) to its root URL configuration. Which statement is correct?

  53. Question 53 of 60 Login and Logout URLs in Django Hard

    After successful authentication, LoginView receives next=https://evil.example/collect, while the current host is app.example.com and the external host is not allowed. What should Django do?

  54. Question 54 of 60 Login and Logout URLs in Django Hard

    LoginView is configured with redirect_authenticated_user=True, and its resolved success URL points back to the same login URL. What protection does Django apply for an already authenticated visitor?

  55. Question 55 of 60 Login and Logout URLs in Django Hard

    A project sets LOGIN_REDIRECT_URL = "/dashboard/" and LOGOUT_REDIRECT_URL = "/signed-out/". No valid next value or view-level override is supplied. What are the resulting destinations?

  56. Question 56 of 60 Using Django Login in Views Hard

    An unauthenticated request reaches a view protected by @login_required. The request includes its own query string. Which behavior correctly describes the generated login redirect?

  57. Question 57 of 60 Using Django Login in Views Hard

    A class-based view inherits from both LoginRequiredMixin and UpdateView. Which inheritance order is required so that the authentication check participates correctly in method dispatch?

  58. Question 58 of 60 Using Django Login in Views Hard

    A custom login view retrieves a user directly with get_user_model().objects.get(...) and then calls login(request, user). Multiple authentication backends are configured, and no backend is stored on the user. What is required?

  59. Question 59 of 60 Using Django Login in Views Hard

    A view stores shopping-cart data in request.session and then calls django.contrib.auth.logout(request). What happens to that session data?

  60. Question 60 of 60 Using Django Login in Views Hard

    An anonymous visitor has cart data in the session. The application authenticates the visitor and calls login(request, user) for a valid user, with no conflicting authenticated-user data in the session. What normally happens?

That's unit 6

Answer a few questions and your score shows up here.