NEW
Font size
WorksheetsFullStack Django - [26 Apr 24] TEST - 2
Total questions: 45
Worksheet time: 45mins
What are Migrations in Django?
Migrations are files where Django stores changes to your models.
They are files saved in migrations directory.
They are created when you run makemigrations command.
All of the above
Which Django functions are used to take http requests and return http responses?
Django views
Django templates
Django request() and response()
Both A and C
In Django, data is created in ____.
tables
templates
views
objects
In Django, data is created in objects, what are these objects called ____.
database
templates
models
views
Which is the correct statement to import models in the Django project?
from django import models
from django.models import models
from django.db import models
None of the above
What is the correct syntax to use a variable in the Django template?
< variable_name >
{{ variable_name }}
" variable_name "
<< variable_name >>
How you can turn off the debugging in Django's configuration file?
DEBUGOFF = True
DEBUG = FALSE
DEBUG = False
DEBUG = false
Which template tag is used to create variables directly in the Django template?
{% with %}
{{ with }}
<% with %>
<< with >>
How many parameters do render() function take in Django?
1
2
3
4
Which is the correct import statement to use the render() function in Django?
from django.shortcuts import render
from django import render
from django.requests import render
from httpresponses import render
Except Django comment tag, what can be used to write smaller comments?
# ..
/* … *
{{# ... #}}
{# ... #}
Which Django keyword is used to send variables into the template?
send
export
go
with
In Django QuertSet, how to add two search queries?
By using the comma separator
By using the + symbol
By using the AND keyword
By using the OR keyword
How does Django handle URL routing?
By using regular expressions
By using functions
By using a fixed path
By using classes
What does the Django ORM (Object-Relational Mapping) do?
Provides data validation
Maps objects to relational database tables
Manages database connections
Maps relational database tables to objects
What is Django's template language used for?
URL routing
Dynamic HTML generation
Object-Relational Mapping
Data validation
How does Django protect against CSRF (Cross-Site Request Forgery) attacks?
By using SSL/TLS
By using a secret key
By using a fixed path
By using a unique token for each request
What is Django's admin app used for?
Serving static files
Generating dynamic HTML
Handling user authentication
Providing an interface for managing application data
What is Django's security principle "Don't trust the client"?
The client always knows what it is doing
All data received from the client should be validated before use
Data stored on the client is always secure
The client cannot be trusted to provide correct data
What is the purpose of Django's manage.py file?
To run the development server
To manage project-level configuration and tasks
To handle URL routing
To serve static files
How does Django handle user authentication?
By relying on an external authentication service
Through the use of a custom authentication backend
By providing a built-in authentication system
By using the Django ORM
What is the purpose of Django's asgi module?
To enable Django to work with asynchronous code
To handle URL routing
To manage project-level tasks
To serve static files
What is the preferred way to start a new Django project?
Manually creating all necessary files and directories
Using the Django startproject command
Copying an existing project
Using a code editor's project template
What is the purpose of the "init.py" file in Django?
To store the app's models
To store the app's views
To initialize the app
To store the app's forms
What is the purpose of the "migrations" folder in Django?
To store the project's views
To store the project's models
To store the project's static files
To store the project's database migrations
How do you make a Django model available for use in the admin interface?
By registering the model in the "admin.py" file of the app
By registering the model in the "settings.py" file of the project
By registering the model in the "models.py" file of the app
By registering the model in the "urls.py" file of the project
What does {% include %} does?
It will include another template.
It will include content from another template having the same templates defined.
It is the same as {% extend %}.
None of the above
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
It displays a human-readable form of object.
It will display the post_heading when str() is called.
It will return the name of the post when Post object is printed.
None of the above
In Post.models.filter() you can pass multiple parameters in filter() to narrow your result/s.
True
False
What effect does _ contains does in this parameter?
from post.models import *
m = Post.objects.filter(postheading__contains=”post”)
m
It will select all the posts having post in their post_heading name.
It will search for field post_heading__contains and match value with them.
It will return the first object it matched the value with.
It will throw an error as no post_heading__contains field does not exist.
What does admin.autodiscover() do?
It will look through INSTALLED_APPS when admin is requested.
If the installed apps have admin.py it will execute them.
Both a and b
None of the above
What kind of non-HTML outputs can Django generate?
.epub Files
Sitemaps (an XML format developed by google)
Exe files
Python files
What are request.GET and request.POST objects?
Python Dictionaries
Python Lists
Python Dictionary-Like objects
None of the above
Which code will give us a text area form field?
Field_name = forms.TextAreaField()
Field_name = forms.CharField(widgets = forms.Textarea)
Field_name = forms.TextField(widgets = forms.Textarea)
None of the above
Suppose you want to count the number of books in Django.
books = Book.objects.all()
Which implementation would be fastest?
Database level Implementation – books.count()
Python Implementation – len(books)
Template Language Implementation – {{ books | length }}
None of the above
Which of these is not a valid method or approach to perform URL resolution?
Using Template {{ url : }} in template
Using reverse() in View Functions
Using get_absolute_url()
None of the above
Which of the following Password Validators are not provided by default in Django?
NumericPasswordValidator
CommonPasswordValidator
MinimumLengthValidator
MaximumLengthValidator
Which of these are not built-in Validators in Django?
MinLengthValidator
EmailValidator
ProhibitNullCharacterValidator
None of the above
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?
The program stops executing and Django server stops.
The clean() method stops validation and returns a list of validation errors.
The clean() method continues execution and catches all the validation errors in that form.
The clean() method catches the validation error and corrects it.
What happens when url.py file is edited while the development server is still running?
Development server terminates.
The development server automatically restarts.
The development server does nothing.
The web page is automatically reloaded.
Which setting contains the parameter of main-urls file?
ROOT_URLCONF
MAIN_URLCONF
STATIC_URL
MEDIA_URL
Which method is used instead of path() in urls.py to pass in regular expressions as routes?
static()
re_path()
include()
url()
Check in-valid template tag.
{% If %}/ {% else %}
{% ifequal %}
{% while %} – wrong
{% for key in dictionary %}
What does {{ forloop.counter }} prints?
It will not print if for loop variable is not defined.
It will count the number of times loop ran.
It prints the integer value of no. of times the loop executed.
None of the above
