Django Upwork Test

0
405

We don’t guarantee that all provided answers are correct.

Which of the following is not a layer in Django?
Answer

  • Models
  • Views
  • Templates
  • Controller
  • None of the above

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
Answer

  • HttpResponseNotAllowed
  • HttpResponseForbidden
  • HttpResponseBadRequest
  • No exception will be raised

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

  • 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)

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

  • pip
  • manage.py
  • django­admin.py
  • easy_install

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

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

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

  • MySQL
  • PostgreSQL
  • MongoDb
  • DynamoDb

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

Answer

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

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

  • 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 query gives the count of vehicles that are private?
Answer

  • Vehicles.objects.fillter(private=True).count()
  • Vehicles.objects.fillter(private=True)
  • Vehicles.objects.fillter(private=True).aggregate(Count(‘id’))
  • Both 1 and 2
  • Both 1 and 3

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

  • 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

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

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

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

  • List
  • Tuple
  • Dictionary
  • Set
  • String

Django is written in
Answer

  • Python
  • C
  • C++
  • Python and C

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

  • Many to one: each instance of A belongs to an instance of B
  • One to many: each instance of B belongs to an instance of A
  • One to one: each instance of A corresponds to a unique instance of B
  • All of the above

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

  • Validate Error
  • Integrity Error
  • ObjectDoesNotExists
  • FieldError

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

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

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

  • Mod_WSGI
  • uWSGI
  • Ansible
  • Gunicorn

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

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

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

  • 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

Which of the following is not true about testing
Answer

  • 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

How can you set up static files in Django?
Answer

  • 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 of the following is the correct way to specify a translation string
Answer

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

What does setting SESSION_COOKIE_SECURE = True do
Answer

  • 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

Assume a, b, c, d and e variable which hold some integer from 1 to 10. which of the following is not correct in django template
Answer

  • {% 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 features are supported by Django
Answer

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

Which of the following are determined by Django using field class types?
Note: There may be more than one right answer.
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 random order a queryset?
Answer

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

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

  • request_started
  • pre_saved
  • m2m_changed
  • pre_modified

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

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

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

  • Staff users
  • Super users
  • Super users and staff users
  • All users

How is the ManyToManyField represented in Django model form?
Answer

  • CharField
  • ModelChoiceField
  • ModelMultipleChoiceField
  • Checkbox

What is true about the management command collect static?
Answer

  • 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

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

  • base
  • lower
  • join
  • extend
  • include

Which of the following is NOT correct about Django Models?
Answer

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

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

  • @permission_required
  • @is_authenticated
  • @user_passes_test
  • @permissions
  • @login_required

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

Answer

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

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

  • MySQL
  • PostgreSQL
  • MongoDb
  • DynamoDb

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

  • Session management
  • CSRF Protection
  • Content Gzipping
  • All of the above

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

  • phython manage.py makemigration
  • python manage.py migrate
  • python manage.py shell
  • None of the mentioned

Select all correct ways to add a message.
Note: There may be more than one right answer.
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.’)

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.