Django Test Upwork

Which of the following statements is true about the django.template.RequestContext class?

It takes a Context object as its first argument.
It takes an HttpRequest as its first argument.
It does not automatically the context with variables.
It can only be given one context processor.

Which is the correct way to start a new django project? Assume the new project is called ‘myproject’.

django startproject myproject
django-admin startproject myproject
django newproject myproject
startproject django myproject

What is the exception raised when the object is not found while performing the following query?
Poll.objects.get(id=1)

    Validate Error
    Integrity Error
    ObjectDoesNotExists
    FieldError

What is the correct way to random order a queryset?

    order_by(”)
    order_by(‘?’)
    order_by(None)
    None of the mentioned

Which of the following features are supported by Django?

Development Environment
Administration GUI
Multilingual system
Object Relational Mapping (ORM
All of the mentioned

Which data structure is used to pass context values from views to template?

List
Tuple
Dictionary
Set
String

Which of the following methods is not used in Django ListView?

get_object
get_context_data
get_queryset
get

Which is the correct way to allow empty value in CharField?

models.CharField(max_length=10)
models.CharField(max_length=10, blank=True)
models.CharField(max_length=10, null=True)
models.CharField(max_length=10, blank=True, null=True)

Which is the correct way to allow empty value in Integer Field?

models.IntegerField()
models.IntegerField(blank=True)
models.IntegerField(null=True)
models.IntegerField(blank=True, null=True)

Which of the following is NOT used as a server for django in production?

Mod_WSGI
uWSGI
Ansible
Gunicorn

Which database is not supported by Django ORM?

Mysql
Postgresql
Mongodb
Oracle

Which of the following database is not supported by Django ORM?

MySQL
PostgreSQL
MongoDb
DynamoDb

Which of the following caching strategies can be implemented in Django?

File system caching
Local-memory caching
Using Memcached
Database caching
All of the above

Which of the following caching strategies are supported in Django? (check any that apply)
Note: There may be more than one right answer.

File sytem caching
Proxy models
Makemigrations
In-memory caching

Which of the following is a possible usage of middlewares in Django?

Session management
CSRF Protection
Content Gzipping
All of the above

How can you hide the author field and assign a currently logged in user to be the author when creating posts?

[forms.py]
class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        exclude = (‘author’,)
[views.py]
def home(request, template_name=’post/home.html’):
    if request.method == ‘POST’:
        post_form = PostForm(request.POST) if post_form.is_valid():
        post_form.save()
    else:
        post_form =PostForm(initial={‘author’: request.user})

[forms.py]
class PostForm(forms.ModelForm):
    author = forms.ModelChoiceField(queryset=User.objects.all(), required=True, widget=forms.HiddenInput())
    class Meta:
        model = Post
[views.py]
def home(request, template_name=’post/home.html’):
    if request.method == ‘POST’:
        post_form = PostForm(request.POST) if post_form.is_valid():
        post_form.save()
    else:
        post_form = PostForm(initial={‘author’: request.user})

[forms.py]
class PostForm(forms.ModelForm):
    author = forms.HiddenInput()
    class Meta:
        model = Post
[views.py]
def home(request, template_name=’post/home.html’):
    if request.method == ‘POST’:
        post_form = PostForm(request.POST) if post_form.is_valid():
        post_form.save()
    else:
        post_form = PostForm(initial={‘author’: request.user})

[forms.py]
class PostForm(forms.ModelForm):
    author = forms.ModelChoiceField(queryset=User.objects.all(), required=True, widget=forms.HiddenInput())
    class Meta:
        model = Post
[views.py]
def home(request, template_name=’post/home.html’):
    if request.method == ‘POST’:
        post_form = PostForm(request.POST) if post_form.is_valid():
        post_form.save()
    else:
        post_form = PostForm()

What does setting SESSION_COOKIE_SECURE = True do?

Ensures cookie can be sent on HTTP connection only
Ensures cookie can be sent on HTTPS connection only
Ensures cookie can be sent on any connection
Disables cookie

What is TRUE about django-admin.py makemessages command?

Updates all messages in the database.
Pulls out all the strings marked for translation and makes a message file in the locale directory.
Both of the above
None of the above

Which of the following is NOT used to represent ManyToManyField in Django model form? Check all that apply.
Note: There may be more than one right answer.

Charfield
ModelChoiceField
ModelMultipleChoiceField
Checkbox

How is the ManyToManyField represented in Django model form?

CharField
ModelChoiceField
ModelMultipleChoiceField
Checkbox

How would you check if a list my_list is empty or not in template ?

{% if my_list %} {% endif %}
{% if my_list|length > 0 %} {% endif %}
Both 1 and 2
None of the mentioned

What kind of relation is defined between models A and B by invoking ForeignKey(A) in the class definition for model B?

Many to one: Many instances of B can have one instance of A
One to many: One instance of B can have many instances of A
One to one: One instance of B must have a unique instance of A and vice versa
All of the above

Which of the following is true for model field names?

A field name cannot be a Python reserved word
A field name cannot contain more than one underscore in a row
Both of the above
None of the above

Using a template tag you tried to load a templatetag as in {% load poll_extras %} and it failed, what could be the problem ?

You used the load in the wrong place of the page
You passed the limit of template tags
The app that contain the template tag is not in INSTALLED_APPS
All of the above

Which form method binds the data in the URL and is passed to the view?

GET
POST
Both of the above
None of the above

What command line can be used to load data into Django?

Admin.py loaddata
Django-admin.py loaddata
Djangoadmin loaddata
Django-admin load data

What is the exception raised if you are using POST against this function?
from django.views.decorators.http
import require_http_methods
@require_http_methods(["GET", "POST"])
def my_view(request):
    pass

HttpResponseNotAllowed
HttpResponseForbidden
HttpResponseBadRequest
No exception will be raised

Which of the following will not register a model "Test" to Django admin?

admin.site.register(Test)
admin.site.register(Test, TestAdmin)
admin(Test)
@admin.register(Test)
class TestAdmin(admin.ModelAdmin):
    pass

What is the correct way to insert csrf token for forms in Django template?

<form action="" method="post">{% csrf_token %}
{% csrf_token %}<form action="" method="post">
<form action="" method="post" {{csrf_token }}>
<form action="" method="post"></form>{% csrf_token %}

Which of the following is the correct way to specify a translation string?

by using the function ugettext()
by using the function ugettext_lazy()
Both of the above
None of the above

Which template command makes a custom template tag/filter available in template?

{% load %}
{% include %}
{% extend %}
None of the mentioned

What is the full form of FBV and CBV?

Function Based Views &  Class Based Views
Function Behind Views & Class Behind Views
Function Before Views &  Class Before Views
None of the mentioned

What is the exception raised for this query Entry.objects.filter(blog_id=4)?

SyntaxError
MultipleObjectsReturned
MultipleModelReturned
TypeError

Django is a web __ in Python used to develop a web application.

Programming
Framework
API
Library

Which decorators are used to restrict authentication of users?
Note: There may be more than one right answer.

@permission_required
@is_authenticated
@user_passes_test
@permissions
@login_required

Which types of users are allowed to login to the Django administration site?

Staff users
Super users
Super users and staff users
All users

Which of the following are determined by Django using field class types?
Note: There may be more than one right answer.

The database column type
The default HTML widget to avail while rendering a form field
Makemigrations
All of the above

What is the correct way to specify the fields to use in a Model Form?

Using fields attribute that specifies list of model fields in the form’s Meta class     ?
Using exclude attribute in the form’s Meta class
Either 1 or 2
None of the mentioned

If an instance of a form is named ‘form’, which attribute of form instance holds all validated form data?

form.is_valid
form.cleaned_data
form.clean_data
form.data

How can you set up static files in Django?

set STATIC_ROOT in settings.py
run manage.py collectsatic
set up a Static Files entry on the PythonAnywhere web tab
All of the above

Which template tag is used to add another template to the current one?

base
lower
join
extend
include

What is the table name for a model named Choice in the application?

choice_question
questionchoice
choicequestion
question_choice

Which of the following is NOT correct about Django Models?

Each model is a Python class that subclasses django.db.models.Model.
Each attribute of the model represents a database field.
The name of the table is automatically derived from some model metadata and can not be overridden.
None of the mentioned

Select all correct ways to add a message.
Note: There may be more than one right answer.

messages.add_message(request, messages.INFO, 'Hello world.')
messages.append(request, messages.INFO, 'Hello world.')
messages.info(request, 'Hello world.')
messages.success(request, 'Hello world.')

Which of the following is not true about testing?

Separate, blank databases are created for tests.
The command used to run all unit tests is
./manage.py test --all
Django’s unit tests use a Python standard library module called unittest
We can use a custom name for the test database by specifying NAME in the TEST dictionary in settings.

Which command runs all tests in a Django project?

python manage.py runalltests
python manage.py test
python manage.py test --all
None of the mentioned

How would you iterate through a list called my_list in template ?

{% for x in my_list %} {% endfor %}
{% items in my_list %} {% items %}
{% iterate my_list as item %} {% enditerate %}
{% while my_list %} {% endwhile %}
{% cycle my_list as item %}

Which of the following url patterns is used to register admin urls?

url(r'^admin/', include(admin.site.urls))
url(r'^admin/', include(admin.urls))
url(r'^admin/', include(admin))
url(r'^admin/', include(site.urls))

What is the correct way to Abstract Model class?

Add abstract=True in Meta class
Add field name abstract=True
Inherit from Abstract
Override the abstract method

Assume a, b, c, d and e are variables which hold some random integer from 1 to 10. Which of the following is NOT correct in django template?

{% if a == b or c == d and e %}
{% if a > b > c %}
{% if a > b and b > c %}
None of the mentioned

Which of the following is not True?

The content types application in django can track all of the models installed in your Django-powered project.
The flatpages application in django lets you store simple “flat” HTML content in a database.
The sites framework is a holding place for the domain names and “verbose” names of your Django-powered sites.
Django does not support Unicode data everywhere.

Which Django core function can be used to send an email?

django.core.mail.send_mail
django.core.email.send_mail
django.core.mail.send_email
None of the mentioned

Which query gives the count of vehicles that are private?

Vehicle.objects.filter(private=True).count()
Vehicle.objects.count(private=True)
Vehicle.objects.filter(private=True).aggregate(Count(‘id’))
Both 1 and 2
Both 1 and 3

How do you inherit the A.html template in B.html template?

In B template, use {% extends "A.html" %}
In A template, use {% extends "B.html" %}
In B template, use {% extends "B.html" %}
None of the mentioned

Which of the following is not a layer in Django?

Models
Views
Templates
Controller
None of the above

What is the name of the command line tool that Django provides for managing a newly created project and its applications?

pip
manage.py
django­admin.py
easy_install

Which is the correct way to start a new app inside a django project? [assume new app is called ‘myapp’]

python manage.py startapp myapp
python manage.py start myapp
django-admin.py startapp myapp
python manage.py new myapp

How can you access a variable in template which is passed from view? Suppose the variable name is object.

{object}
{{object}}
{% object %}
None of the mentioned

What is true about the management command collectstatic?

Takes all of the static files of your project and puts them in the folder specified in STATIC_ROOT so they can be served in production.
Collect all static files and display the count.
Both 1 and 2
None of the mentioned

Check all True facts about Django.
Note: There may be more than one right answer.

Written in Python
Desktop Application Framework
Web Application Framework
All of the above

Which of the following are valid built-in signals provided by Django? Check all that apply.
Note: There may be more than one right answer.

request_started
pre_saved
m2m_changed
pre_modified

Which of the following are built-in signal provided by Django?

request_started
pre_save
m2m_changed
pre_delete
All of the above

Which of the following commands will  make changes in the database tables schema?

python manage.py makemigrations
python manage.py migrate
python manage.py shell
None of the mentioned

Which of the following is true about generators?

Generators must contain a previous statement
Generators must contain a yield statement
Generators must contain a next statement
All of the above

Which is the correct way to create a superuser from command line?

python manage.py create superuser
python manage.py createsuperuser
python manage.py superuser create
None of the mentioned

Which of the following statements is true about the QuerySet select_related() method?

Returns a QuerySet that will “follow” foreign-key relationships, selecting additional related-object data when it executes its query.
Returns a QuerySet that will automatically retrieve, in a single batch, related objects for each of the specified lookups.
Returns a new QuerySet containing objects that do not match the given lookup parameters.
None of the mentioned

Which attribute is used to order the objects in django admin?

order
order_by
ordering
ordered

Which query includes a shirt with size 40?

Shirt.objects.filter(size__gt=40)
Shirt.objects.count(size__lte=40)
Shirt.objects.filter(size==40)
Both 1 and 2
Both 2 and 3

What is the exception raised when a duplicate value is used in unique field while inserting a record?

ValidationError
IntegrityError
ObjectDoesNotExist
FieldError

Django  Test Upwork 2019