wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

FullStack Django - [26 Apr 24] TEST - 2

Total questions: 45

Worksheet time: 45mins

Name
Class
Date
1.

What are Migrations in Django?

a)

Migrations are files where Django stores changes to your models.

b)

They are files saved in migrations directory.

c)

They are created when you run makemigrations command.

d)

All of the above

2.

Which Django functions are used to take http requests and return http responses?

a)
  1. Django views

b)
  1. Django templates

c)
  1. Django request() and response()

d)
  1. Both A and C

3.

In Django, data is created in ____.

a)
  1. tables

b)
  1. templates

c)
  1. views

d)

objects

4.

In Django, data is created in objects, what are these objects called ____.

a)

database

b)
  1. templates

c)
  1. models

d)

views

5.

Which is the correct statement to import models in the Django project?

a)
  1. from django import models

b)
  1. from django.models import models

c)
  1. from django.db import models

d)

None of the above

6.

What is the correct syntax to use a variable in the Django template?

a)
  1. < variable_name >

b)
  1. {{ variable_name }}

c)
  1. " variable_name "

d)
  1. << variable_name >>

7.

How you can turn off the debugging in Django's configuration file?

a)
  1. DEBUGOFF = True

b)
  1. DEBUG = FALSE

c)
  1. DEBUG = False

d)
  1. DEBUG = false

8.

Which template tag is used to create variables directly in the Django template?

a)
  1. {% with %}

b)
  1. {{ with }}

c)
  1. <% with %>

d)
  1. << with >>

9.

How many parameters do render() function take in Django?

a)

1

b)

2

c)

3

d)

4

10.

Which is the correct import statement to use the render() function in Django?

a)
  1. from django.shortcuts import render

b)
  1. from django import render

c)
  1. from django.requests import render

d)
  1. from httpresponses import render

11.

Except Django comment tag, what can be used to write smaller comments?

a)
  1. # ..

b)
  1. /* … *

c)
  1. {{# ... #}}

d)
  1. {# ... #}

12.

Which Django keyword is used to send variables into the template?

a)
  1. send

b)
  1. export

c)
  1. go

d)
  1. with

13.

In Django QuertSet, how to add two search queries?

a)
  1. By using the comma separator

b)
  1. By using the + symbol

c)
  1. By using the AND keyword

d)
  1. By using the OR keyword

14.

How does Django handle URL routing?

a)

By using regular expressions

b)

By using functions

c)

By using a fixed path

d)

By using classes

15.

What does the Django ORM (Object-Relational Mapping) do?

a)

Provides data validation

b)

Maps objects to relational database tables

c)

Manages database connections

d)

Maps relational database tables to objects

16.

What is Django's template language used for?

a)

URL routing

b)

Dynamic HTML generation

c)

Object-Relational Mapping

d)

Data validation

17.

How does Django protect against CSRF (Cross-Site Request Forgery) attacks?

a)

By using SSL/TLS

b)

By using a secret key

c)

By using a fixed path

d)

By using a unique token for each request

18.

What is Django's admin app used for?

a)

Serving static files

b)

Generating dynamic HTML

c)

Handling user authentication

d)

Providing an interface for managing application data

19.

What is Django's security principle "Don't trust the client"?

a)

The client always knows what it is doing

b)

All data received from the client should be validated before use

c)

Data stored on the client is always secure

d)

The client cannot be trusted to provide correct data

20.

What is the purpose of Django's manage.py file?

a)

To run the development server

b)

To manage project-level configuration and tasks

c)

To handle URL routing

d)

To serve static files

21.

How does Django handle user authentication?

a)

By relying on an external authentication service

b)

Through the use of a custom authentication backend

c)

By providing a built-in authentication system

d)

By using the Django ORM

22.

What is the purpose of Django's asgi module?

a)

To enable Django to work with asynchronous code

b)

To handle URL routing

c)

To manage project-level tasks

d)

To serve static files

23.

What is the preferred way to start a new Django project?

a)

Manually creating all necessary files and directories

b)

Using the Django startproject command

c)

Copying an existing project

d)

Using a code editor's project template

24.

What is the purpose of the "init.py" file in Django?

a)

To store the app's models

b)

To store the app's views

c)

To initialize the app

d)

To store the app's forms

25.

What is the purpose of the "migrations" folder in Django?

a)

To store the project's views

b)

To store the project's models

c)

To store the project's static files

d)

To store the project's database migrations

26.

How do you make a Django model available for use in the admin interface?

a)

By registering the model in the "admin.py" file of the app

b)

By registering the model in the "settings.py" file of the project

c)

By registering the model in the "models.py" file of the app

d)

By registering the model in the "urls.py" file of the project

27.

What does {% include %} does?

a)
  • It will include another template.

b)
  • It will include content from another template having the same templates defined.

c)
  • It is the same as {% extend %}.

d)
  • None of the above

28.

What is the purpose of str() method?
class Post(models.Model):
    post_heading = models.CharField(max_length=200)
    post_text = models.TextField()
    post_author = models.CharField(max_length=100, default=’anonymous’)

    def str(self):
        return self.post_heading

a)
  • It displays a human-readable form of object.

b)
  • It will display the post_heading when str() is called.

c)
  • It will return the name of the post when Post object is printed.

d)
  • None of the above

29.

In Post.models.filter() you can pass multiple parameters in filter() to narrow your result/s.

a)

True

b)

False

30.

What effect does _ contains does in this parameter?
from post.models import *
m = Post.objects.filter(post
heading__contains=”post”)
m

a)
  • It will select all the posts having post in their post_heading name.

b)
  • It will search for field post_heading__contains and match value with them.

c)
  • It will return the first object it matched the value with.

d)
  • It will throw an error as no post_heading__contains field does not exist.

31.

What does admin.autodiscover() do?

a)
  • It will look through INSTALLED_APPS when admin is requested.

b)
  • If the installed apps have admin.py it will execute them.

c)
  • Both a and b

d)
  • None of the above

32.

What kind of non-HTML outputs can Django generate?

a)
  • .epub Files

b)
  • Sitemaps (an XML format developed by google)

c)
  • Exe files

d)
  • Python files

33.

What are request.GET and request.POST objects?

a)
  • Python Dictionaries

b)
  • Python Lists

c)
  • Python Dictionary-Like objects

d)
  • None of the above

34.

Which code will give us a text area form field?

a)
  • Field_name = forms.TextAreaField()

b)
  • Field_name = forms.CharField(widgets = forms.Textarea)

c)
  • Field_name = forms.TextField(widgets = forms.Textarea)

d)
  • None of the above

35.

Suppose you want to count the number of books in Django.
books = Book.objects.all()
Which implementation would be fastest?

a)
  • Database level Implementation – books.count()

b)
  • Python Implementation – len(books)

c)
  • Template Language Implementation – {{ books | length }}

d)
  • None of the above

36.

Which of these commands is not a management command of staticfiles?

a)
b)
c)
d)
37.

Which of these is not a valid method or approach to perform URL resolution?

a)
  • Using Template {{ url : }} in template

b)
  • Using reverse() in View Functions

c)
  • Using get_absolute_url()

d)
  • None of the above

38.

Which of the following Password Validators are not provided by default in Django?

a)
  • NumericPasswordValidator

b)
  • CommonPasswordValidator

c)
  • MinimumLengthValidator

d)
  • MaximumLengthValidator

39.

Which of these are not built-in Validators in Django?

a)
  • MinLengthValidator

b)
  • EmailValidator

c)
  • ProhibitNullCharacterValidator

d)
  • None of the above

40.

When we execute form.clean() on a form object and suppose at any point validation error is raised by a validator. What happens after the Validation Error occurs?

a)
  • The program stops executing and Django server stops.

b)
  • The clean() method stops validation and returns a list of validation errors.

c)
  • The clean() method continues execution and catches all the validation errors in that form.

d)
  • The clean() method catches the validation error and corrects it.

41.

What happens when url.py file is edited while the development server is still running?

a)
  • Development server terminates.

b)
  • The development server automatically restarts.

c)
  • The development server does nothing.

d)
  • The web page is automatically reloaded.

42.

Which setting contains the parameter of main-urls file?

a)
  • ROOT_URLCONF

b)
  • MAIN_URLCONF

c)
  • STATIC_URL

d)
  • MEDIA_URL

43.

Which method is used instead of path() in urls.py to pass in regular expressions as routes?

a)
  • static()

b)
  • re_path()

c)
  • include()

d)
  • url()

44.

Check in-valid template tag.

a)
  • {% If %}/ {% else %}

b)
  • {% ifequal %}

c)
  • {% while %} – wrong

d)
  • {% for key in dictionary %}

45.

What does {{ forloop.counter }} prints?

a)
  • It will not print if for loop variable is not defined.

b)
  • It will count the number of times loop ran.

c)
  • It prints the integer value of no. of times the loop executed.

d)
  • None of the above