Do you know that? 66% of those who have been freelancing for 10 years or longer felt strongly about being self-employed next

Contact Email:

<< All Upwork (oDesk) and Elance Tests << Elance test answers << IT & Programming category

Test answers for Django 2020

(61) Last updated: January 23
Elance • IT & Programming
Questions and answers are regularly updated. Answered and not answered tests questions.

This helps getting job: Hundreds of (cover letter examples , interview questions , profile samples ) • Earn on Upwork (oDesk)
Job assistance: jobs popularityfreelance rates

Popular test answers: HTML, .Net, CSS, English, SEO, Photoshop, iOS, Java, Android, Ruby, Python, JavaScript

See all 6 tests answers updated

Find Upwork (oDesk) and Elance test answers on this website:

Collapse | Expand

61 Answered Test Questions:

1. What is the command to start Django's built-in development server?


• startserver --dev

• --run

• run

• runserver

• --start

2. Given a model named 'User' that contains a DateTime field named 'last_login', how do you query for users that have never logged in?


• User.objects.filter( last_login__isnull=False )

• User.objects.filter( last_login=Null )

• User.objects.filter( last_login=Never )

• User.objects.filter( last_login__isnull=True )

• User.objects.filter( last_login__null=True )

3. How can you define additional behavior and characteristics of a Django class?


• class __init__:

• def Meta():

• def setUp():

• def __init__():

• class Meta:

4. What happens if MyObject.objects.get() is called with parameters that do not match an existing item in the database?


• The object is created and returned.

• The Http404 exception is raised.

• The MyObject.DoesNotExist exception is raised.

• The DatabaseError exception is raised.

5. How to make django timezone-aware?


• In USE_L10N=True

• in, import timezone

• In USE_TZ=True

• in, import timezone

• in, import tz

6. Assuming you have a Django model named 'User', how do you define a foreign key field for this model in another model?


• user = models.ForeignKey(User)

• user = models.IntegerKey(User)

• model = new ForeignKey(User)

• models.ForeignKey( self, User )

7. What is the command to start a new Django project called 'myproject'?


• startproject myproject

• --start myproject

• startproject myproject

• --new myproject

• new myproject

8. What does the Django command ` shell` do?


• Starts a Python command prompt with your Django environment pre-loaded.

• Loads a special Pythonic version of the Bash shell.

• Loads a Python command prompt you can use to sync your database schema remotely.

• Starts a Django command prompt with your Python environment pre-loaded.

• Starts a command line in whatever $SHELL your environment uses.

9. In Django how would you retrieve all the 'User' records from a given database?


• Users.objects.all()

• User.objects.all()

• User.objects

• User.all_records()

• User.object.all()

10. What preferred method do you add to a Django model to get a better string representation of the model in the Django admin?


• __translate__

• to_s( self )

• __utf_8__

• __unicode__

11. Assuming you've imported the proper Django model file, how do you add a 'User' model to the Django admin?


• Admin )

• admin.register( Users )

• User )

• self, User )

• Admin )

12. What is the most easiest, fastest, and most stable deployment choice in most cases with Django?



• mod_wsgi

• FastCGI


13. How do you exclude a specific field from a ModelForm?


• Use the exclude parameter in the Meta class in your form

• Set the field to hidden

• You can not do this

• Create a new Form, don't use a ModelForm

14. A set of helpful applications to use within your Django projects is included in the official distribution. This module is called what?


• django.ponies

• django.utilities

• django.helpers

• django.extras

• django.contrib

15. What is the purpose of


• To set the date and time on the server

• To sync the database schema

• To configure settings for an app

• To configure settings for the Django project

16. What is ModelForm used for?


• To specify rules for correct form when writing Django code

• To model an input form for a template

• To define a form based on an existing model

17. What is the definition of a good Django app?


• A good Django app is a fully functioning website that has 100% test coverage.

• A good Django app provides a small, specific piece of functionality that can be used in any number of Django projects.

• A good Django app is highly customized and cannot be used in multiple projects.

18. What is the correct syntax for including a class based view in a URLconf?


• (r'^pattern/$', YourView()),

• (r'^pattern/$', YourView.as_view()),

• (r'^pattern/$', YourView),

• (r'^pattern/$', YourView.init()),

19. What is the Django command to start a new app named 'users' in an existing project?


• startapp users

• start users

• --startapp users

• --newapp users

• newapp users

20. What is the command to run Django's development server on port 8080 on IP address


• --run 8080

• run

• --dev

• runserver

• runserver

21. What does a file do in Django?


• You run this file when you get obscure 404 Not Found errors in your server logs.

• It contains URL matching patterns and their corresponding view methods.

• This file contains site deployment data such as server names and ports.

• It contains a site map of Django-approved URLs.

• This file provides an up to date list of how-to URLs for learning Django more easily.

22. How do you define a 'name' field in a Django model with a maximum length of 255 characters?


• name = models.CharField(max_length=255)

• model = CharField(max_length=255)

• name = models.CharField(max_len=255)

• name = model.StringField(max_length=auto)

• model.CharField(max_length=255)

23. After you make a new 'app' in your existing Django project, how do you get Django to notice it?


• Run the ` syncdb` command.

• No additional action is required, Django notices new apps automatically.

• Run the ` validate` command, and then start a new shell.

• In, add the app to the PROJECT_APPS variable.

• In, add the new app to the INSTALLED_APPS variable.

24. Django is written using what programming language?


• Java


• Ruby

• Python

• Javascript

25. What is the Django shortcut method to more easily render an html response?


• render_to_response

• response_render

• render

• render_to_html

26. What does the Django command ` validate` do?


• Checks for errors in your views.

• Checks for errors in your templates.

• Checks for errors in your file.

• Checks for errors in your models.

• Checks for errors in your controllers.

27. Given the Python data:  mydata = [ [ 0, 'Fred' ], [ 1, 'Wilma' ] ]  How do you access the data in a Django template?


• {{ for d in mydata }} <p><a href="/users/{{ d[0] }}/">{{ d[1] }}</a></p> {{ endfor }}

• {% for d in mydata -%} <p><a href="/users/{{ d.0 }}/">{{ d.1 }}</a></p> {% end -%}

• {% for d in mydata %} <p><a href="/users/{% d.0 %}/">{% d.1 %}</a></p> {% endfor %}

• {% for d in mydata %} <p><a href="/users/{{ d.0 }}/">{{ d.1 }}</a></p> {% endfor %}

• {% mydata.each |d| %} <p><a href="/users/{{ d.1 }}/">{{ d.2 }}</a></p> {% end %}

28. What is the Django command to view a database schema of an existing (or legacy) database?


• inspect

• legacydb

• schemadump

• inspectdb

• inspect

29. What is the correct way to include django's admin urls?   from django.contrib import admin') from django.conf.urls import patterns, include, url  urlpatterns = patterns('',     ______________________ )


• url(r'^admin/', include( ),

• admin.autodiscover()

• url(r'^admin/', include(admin) ),

• url(r'^admin/', admin.as_view(), name='admin ),

• url(r'^admin/', admin.urls ),

30. Given an IntegerField named 'widgets' in the Django model 'User' , how do you calculate the average number of widgets per user?


• User.objects.all().aggregate( Avg( 'widgets' ) )

• Widget.objects.all().aggregate( Avg( 'users' ) )

• User.objects.all().aggregate( Sum( 'widgets' ) )

• User.all().aggregate( Avg( 'widgets' ) ).count()

• User.objects.avg( 'widgets' )

31. What is the Django command to retrieve the first 10 'User' records from your database sorted by name descending?


• User.objects.all().order_by('name')[:10]

• User.objects.all().order_by('-name')[:10]

• User.all().order_by('-name')[10:]

• User.objects.all().order('-name')[10:]

• User.objects.all().order('-name')[:10]

32. What is the purpose of the STATIC_ROOT setting?


• Defines the URL prefix where static files will be served from .

• A project's static assets should be stored here to be served by the development server.

• Defines the location where all static files will be copied by the 'collectstatic' management command, to be served by the production webserver.

• Defines the location for serving user uploaded files.

33. What is the definition of a Django Project?


• A collection of configuration files and individual apps that form a web site.

• A specific piece of functionality that can be used in multiple Django apps.

• A fork of the official Django repo.

• A web site that uses the Django framework.

34. Given a model named 'User' that contains a field named 'email', how do you perform a case-insensitive exact match for the email ''?


• User.objects.filter( email__icontains='' )

• User.objects.filter( email__exact='' )

• User.objects.filter( email__iexact='' )

• User.objects.filter( email__matches='' )

• User.objects.filter( email__contains='' )

35. You have created a Form class and wish to provide custom logic for validating the input in the "foo" field. What would you name your custom validation method?


• clean_foo

• foo_clean

• sanitize_foo

• clean_foo_field

• validate_foo

36. Given a form with field foo, what should the validation method for this field be called?


• foo_is_valid

• validate_foo

• clean_foo

• foo_clean

37. When customizing validation in a Form subclass named MyForm, how do you add an error message that is displayed as a form-wide error?


• Raise ValidationError in MyForm.clean_<fieldname>()

• Raise ValidationError in MyForm.clean()

• Add the error to MyForm._errors in MyForm.clean()

• Add the error to MyForm.errors in MyForm.clean()

38. In, when DEBUG is set to ________, Django will email unhandled exceptional conditions.


• 1

• Never

• True

• False

• Always

39. How do you create a recursive relationship in a model class named 'Company' in Django?


• models.ForeignKey('me')

• models.ForeignKey(Company)

• models.ForeignKey('Company')

• models.ForeignKey('self')

40. You have a Form defined with "password" and "confirm_password" fields. In what method of the "form" object would you validate that the values supplied in these fields match?


• form.sanitize_data

• form.clean

• form.validate

• form.clean_confirm_password

• form.clean_password

41. What is the command used to print the CREATE TABLE SQL statements for the given app name?


• dumpdata myapp

• ./ schema myapp

• ./ sql myapp

• ./ showschema myapp

• ./ showsql myapp

42. What command do you use to alter the fields Django displays for a given model in the Django admin ListView?


• fields_display

• list_display

• auto_list_fields

• list_filter

• fields_list

43. Which class is a model field representing a path to a server-based image file?


• django.db.models.fields.files.ImageFieldFile

• django.db.models.fields.files.ImageFileDescriptor

• django.db.models.fields.files.ImageFileField

• django.db.models.fields.files.ImageFile

• django.db.models.fields.files.ImageField

44. The Benevolent Dictators for Life of the Django Project are:


• Ian Bicking and Jannis Leidel

• and Armando De La Veloper

• Jacob Kaplan-Moss and Adrian Holovaty

• Guido van Rossum and Linus Torvalds

• Eric S. Raymond and Larry Wall

45. Which of these can be used to retrieve a setting from the settings module, and provide a default if the setting is not defined?


• get_setting("SETTING_NAME", default=default_value)

• getattr(settings, "SETTING_NAME", default_value)

• settings.get("SETTING_NAME", default_value)

• getattr("SETTING_NAME", settings, default=default_value)

46. You can handle multiple Django forms with what keyword argument when creating forms?


• name

• suffix

• prefix

• infix

47. In your django template, if you need to get the content of the block from the django parent template, what do you need to add?  {% block my_block %} ___________ {% endblock %}


• {{ block.super }}

• {% super %}

• {% block.super %}

• super (block, self)__init__()

• {{ extends block }}

48. Which type of custom template tag returns a string?


• string_tag

• assignment_tag

• simple_tag

• inclusion_tag

49. A model's "full_clean()" method is called automatically when you call your model's "save()" method.


• False

• True

50. How would you perform a lookup on a model against a database aside from the default?


• Model.objects.database('other').all()

• Model.objects.all(using='other')

• Model.objects.all(database='other')

• Model.objects.using('other').all()

51. Which model field type does NOT exist in Django?


• SmallIntegerField

• LargeIntegerField

• CommaSeparatedIntegerField

• SlugField

• IPAddressField

52. Given a model named 'User' that contains a CharField 'name', how do you query for users whose name starts with 'Fred' or 'Bob'?


• User.objects.filter( name__iregex=r'^(fred|bob)$' )

• User.objects.filter( name__regex=r'^(fred|bob)+' )

• User.objects.filter( name__like=r'^(fred|bob)*' )

• User.objects.filter( name_iregex=r'^(fred|bob)+' )

• User.objects.filter( name__iregex=r'^(fred|bob).+' )

53. How would you create a ForeignKey from a model named Transaction, to a model named Product, with no reverse relation?


• class Transaction(models.Model): product = models.ForeignKey(Product, related_name=None)

• class Transaction(models.Model): product = models.ForeignKey(Product, related_name='+')

• class Transaction(models.Model): product = models.ForeignKey(Product, related_name='')

• class Transaction(models.Model): product = models.ForeignKey(Product, related_name=False)

54. What datetime formatting would you apply in a template to display the following: 2013/03/20 8:00:06 AM  ?


• Y/m/d g:i:s A

• Y-m-d H:m:s

• m/d/Y h:m:s

• Y/m/d H:i

• Y/m/d H:i:s A

55. By using django.contrib.humanize, you can use the following filter in your template to display the number 3 as three.


• naturaltime

• intcomma

• ordinal

• intword

• apnumber

56. What is the name of the Django decorator that hides sensitive info from error reports?


• @sensitive_fields

• @secret_variables

• @sensitive_variables

• @secret_fields

• @hide_fields

57. How to create a DateTimeField named created and filled in only on the creation with the current time?


• created = models.DateTimeField(auto_now=True)

• created = models.DateTimeField(

• created = models.CreationTimeField()

• created = models.DateTimeField(auto_now_add=True)

• created = models.DateTimeField(auto_now_add=True, auto_now=True)

58. Where is pre_save signal in Django


• There is no pre_save signal

• from django.db.models.signals import pre_save

• from django.db.models import pre_save

• from django.db.models.signal import pre_save

59. The django.contrib.contenttypes application provides


• none of the others

• functionality for working with varied file formats

• mimetypes used for returning http responses

• a generic interface for working with models

60. What command compile Django's translation files?


• ./ i18n_update

• ./ compiletranslation

• ./ compilei18n

• ./ compilemessages

• ./ translate_files

61. How to set a default order by in your Django model ? YourModel.objects.all() will be ordered by default without calling order_by() method


• Using META order attribute

• Using META ordering attribute

• Using META default_order attribute

• Using META default_order_by attribute

• Using META order_by attribute