Upwork Django Test 2016.
20 Answered Test Questions:
1. Consider the following Python string representing a human readable date and time:
dt = ‘Jan 14 2009 11:00PM’
1. Consider the following Python string representing a human readable date and time:
dt = ‘Jan 14 2009 11:00PM’
Which of the following code snippets will convert the above string to a Python Datetime object that is suitable for a django.models.DateField?
Answers:
a. date_object = time.strptime(dt, ‘%b %d %Y %I:%M%p’)
a. date_object = datetime.strptime(dt, ‘%b %d %Y %I:%M%p’)
a. date_object = datetime.strptime(dt, ‘%B %D %Y %I:%M%p’)
a. date_object = time.strptime(dt, ‘%b %d %Y %I:%M%p’)
2. Which of the following is false about the django.models.SlugField() model field?
Answers:
a. It is used when performing a query, or as a part of a URL, since by default it ensures uniqueness.
a. To create a slug based on another field automatically in the admin, prepopulated_fields has to be used.
a. It can only contain letters, numbers, underscores or hyphens.
a. Slugs can created in Django templates using the builtin filter, “django.template.defaultfilters.slugify”, formatted as {{ some_text|slugify }}.
3. What does the django.core.context_processors.static() method do?
Answers:
a. It takes a path and urljoins it with the static prefix STATIC_URL.
a. It adds STATIC_URL to every template context rendered with RequestContext contexts.
a. It populates a template variable with the static prefix STATIC_URL to be used as a variable or directly.
a. None of these.
4. Which of the following statements is true about the django.template.RequestContext class?
Answers:
a. It takes a Context object as its first argument.
a. It takes an HttpRequest as its first argument.
a. It does not automatically the context with variables.
a. It can only be given one context processor.
5. Consider two Django QuerySets query_set_1 and query_set_2 from two different models.
Which of the following code snippets is the most performant when concatenating the two QuerySets into one list?
Answers:
a. from itertools import chain result_list = list(chain(query_set_1,query_set_2))
a. result_list = query_set_1 | query_set_2
a. from django.db.models import Q result_list = Q(query_set_1) | Q(query_set_1)
a. from itertools import chain result_list = chain(query_set_1, query_set_2)
6. Which of the following statements about database transactions in Django is false?
Answers:
a. “atomic” blocks allows the creation of blocks of code within which the atomicity on the database is guaranteed.
a. “atomic” blocks cannot be nested.
a. “atomic” can be used as a decorator.
a. “atomic” can be used as a context manager.
7. Consider the following code snippet for a Django Model:
Answers:
a. date_object = time.strptime(dt, ‘%b %d %Y %I:%M%p’)
a. date_object = datetime.strptime(dt, ‘%b %d %Y %I:%M%p’)
a. date_object = datetime.strptime(dt, ‘%B %D %Y %I:%M%p’)
a. date_object = time.strptime(dt, ‘%b %d %Y %I:%M%p’)
2. Which of the following is false about the django.models.SlugField() model field?
Answers:
a. It is used when performing a query, or as a part of a URL, since by default it ensures uniqueness.
a. To create a slug based on another field automatically in the admin, prepopulated_fields has to be used.
a. It can only contain letters, numbers, underscores or hyphens.
a. Slugs can created in Django templates using the builtin filter, “django.template.defaultfilters.slugify”, formatted as {{ some_text|slugify }}.
3. What does the django.core.context_processors.static() method do?
Answers:
a. It takes a path and urljoins it with the static prefix STATIC_URL.
a. It adds STATIC_URL to every template context rendered with RequestContext contexts.
a. It populates a template variable with the static prefix STATIC_URL to be used as a variable or directly.
a. None of these.
4. Which of the following statements is true about the django.template.RequestContext class?
Answers:
a. It takes a Context object as its first argument.
a. It takes an HttpRequest as its first argument.
a. It does not automatically the context with variables.
a. It can only be given one context processor.
5. Consider two Django QuerySets query_set_1 and query_set_2 from two different models.
Which of the following code snippets is the most performant when concatenating the two QuerySets into one list?
Answers:
a. from itertools import chain result_list = list(chain(query_set_1,query_set_2))
a. result_list = query_set_1 | query_set_2
a. from django.db.models import Q result_list = Q(query_set_1) | Q(query_set_1)
a. from itertools import chain result_list = chain(query_set_1, query_set_2)
6. Which of the following statements about database transactions in Django is false?
Answers:
a. “atomic” blocks allows the creation of blocks of code within which the atomicity on the database is guaranteed.
a. “atomic” blocks cannot be nested.
a. “atomic” can be used as a decorator.
a. “atomic” can be used as a context manager.
7. Consider the following code snippet for a Django Model:
class Salary(models.Model):
amount = models.PositiveIntergerField(help_text=’eg 8000′)
retired = models.BooleanField(help_text=’True if above average’)
………..
amount = models.PositiveIntergerField(help_text=’eg 8000′)
retired = models.BooleanField(help_text=’True if above average’)
………..
Which of the following will correctly produce a QuerySet of all Salary objects where retired == True and amount != 7300?
Answers:
a. results = Salary.objects.exclude(retired=true, amount__lt=7300).exclude(retired=true,amount__gt=7300)
a. from django.db.models import Q results = Salary.filter(~Q(amount=7300),retired=True)
a. results = Salary.objects.filtered(retired=True, amount__ne=7300)
a. from django.db.models import Q results = Salary.filter(Q(amount=7300),retired=True)
8. Which of the following gets called when a view raises an exception?
Answers:
a. view_exception()
a. process_exception()
a. execution_exception()
a. controller_exception()
9. What is the best way to extend the Django user model with extra custom fields in addition to the fields already provided?
Answers:
a. Use a a proxy model based on django.contrib.auth.models.User.
a. Subclass django.contrib.auth.models.AbstractUser and add the extra fields.
a. Subclass django.contrib.auth.models.AbstractBaseUser and add the extra fields.
a. Use a one-to-one relationship to a model containing the extra fields.
10. Which of the following statements are true about the ImageField class?
Answers:
a. It inherits all attributes and methods from the FileField class.
a. It validates that the uploaded object is a valid image.
a. Its instances are created as varchar(200) columns in the database.
a. It’s default form widget is a ClearableFileInput.
11. What does the “with” template tag do?
Answers:
a. It adds its argument to the value.
a. It caches a complex under a simpler name.
a. It filters the contents of the blog through one or more filters.
a. None of these.
12. Which of the following statement is false about the django.http.HttpRequest.get_host() method ?
Answers:
a. If DEBUG = False and ALLOWED_HOSTS= [] the method will raise SuspiciousOperation exception resulting in an HTTP Error 500 Internal server error.
a. The method will fail when the host is behind multiple proxies, in this case one solution is to use middleware which will rewrite the proxy headers.
a. This method is invoked if some code accesses the Host header from request.META, thus providing a security measure to prevent an attacker from poisoning caches and password reset emails with links to malicious hosts by submitting requests with a fake HTTP Host header.
a. The method uses information from the HTTP_X_FORWARDED_HOST and HTTP_HOST headers, in that order, or a combination of SERVER_NAME and SERVER_PORT if the latter does not provide a value.
13. What is the default max_length value of a SlugField class in Django?
Answers:
a. 50
a. 100
a. 25
a. 150
14. Which of the following is a built-in BaseCommand subclass?
Answers:
a. AppCommand
a. HelperCommand
a. HandlerCommand
a. DBCommand
15. Which of the following statements is true about Django’s default implementation of the authentication system?
Answers:
a. Django stores passwords in plain text on the user model.
a. It returns a UserAccount object is the password for a given username is authenticated.
a. Permissions can only be set on a per type of object basis.
a. django.contrib.auth will ensure that add, change and delete permissions are created for each Django model defined in an installed application.
16. Which of the following happens when process_exception() returns “None”?
Answers:
a. The template response will be applied.
a. The response middleware will be applied.
a. The default exception handling will be applied.
a. None of these.
17. Which of the following is not a predefined log level in Django?
Answers:
a. DEBUG
a. INFO
a. WARNING
a. FATAL
18. Which of the following classes uses an HTTP 304 status code?
Answers:
a. HttpResponseNotModified
a. HttpResponseRedirect
a. HttpResponseForbidden
a. HttpResponseServerError
19. Which of the following django.template.loader functions will take a list of template names and return the first template that exists?
Answers:
a. find_one_template
a. find_template
a. get_template
a. select_template
20. Which of the following is not a built-in Django template loader class?
Answers:
a. file.Loader
a. cached.Loader
a. eggs.Loader
a. app_directories.Loader
Answers:
a. results = Salary.objects.exclude(retired=true, amount__lt=7300).exclude(retired=true,amount__gt=7300)
a. from django.db.models import Q results = Salary.filter(~Q(amount=7300),retired=True)
a. results = Salary.objects.filtered(retired=True, amount__ne=7300)
a. from django.db.models import Q results = Salary.filter(Q(amount=7300),retired=True)
8. Which of the following gets called when a view raises an exception?
Answers:
a. view_exception()
a. process_exception()
a. execution_exception()
a. controller_exception()
9. What is the best way to extend the Django user model with extra custom fields in addition to the fields already provided?
Answers:
a. Use a a proxy model based on django.contrib.auth.models.User.
a. Subclass django.contrib.auth.models.AbstractUser and add the extra fields.
a. Subclass django.contrib.auth.models.AbstractBaseUser and add the extra fields.
a. Use a one-to-one relationship to a model containing the extra fields.
10. Which of the following statements are true about the ImageField class?
Answers:
a. It inherits all attributes and methods from the FileField class.
a. It validates that the uploaded object is a valid image.
a. Its instances are created as varchar(200) columns in the database.
a. It’s default form widget is a ClearableFileInput.
11. What does the “with” template tag do?
Answers:
a. It adds its argument to the value.
a. It caches a complex under a simpler name.
a. It filters the contents of the blog through one or more filters.
a. None of these.
12. Which of the following statement is false about the django.http.HttpRequest.get_host() method ?
Answers:
a. If DEBUG = False and ALLOWED_HOSTS= [] the method will raise SuspiciousOperation exception resulting in an HTTP Error 500 Internal server error.
a. The method will fail when the host is behind multiple proxies, in this case one solution is to use middleware which will rewrite the proxy headers.
a. This method is invoked if some code accesses the Host header from request.META, thus providing a security measure to prevent an attacker from poisoning caches and password reset emails with links to malicious hosts by submitting requests with a fake HTTP Host header.
a. The method uses information from the HTTP_X_FORWARDED_HOST and HTTP_HOST headers, in that order, or a combination of SERVER_NAME and SERVER_PORT if the latter does not provide a value.
13. What is the default max_length value of a SlugField class in Django?
Answers:
a. 50
a. 100
a. 25
a. 150
14. Which of the following is a built-in BaseCommand subclass?
Answers:
a. AppCommand
a. HelperCommand
a. HandlerCommand
a. DBCommand
15. Which of the following statements is true about Django’s default implementation of the authentication system?
Answers:
a. Django stores passwords in plain text on the user model.
a. It returns a UserAccount object is the password for a given username is authenticated.
a. Permissions can only be set on a per type of object basis.
a. django.contrib.auth will ensure that add, change and delete permissions are created for each Django model defined in an installed application.
16. Which of the following happens when process_exception() returns “None”?
Answers:
a. The template response will be applied.
a. The response middleware will be applied.
a. The default exception handling will be applied.
a. None of these.
17. Which of the following is not a predefined log level in Django?
Answers:
a. DEBUG
a. INFO
a. WARNING
a. FATAL
18. Which of the following classes uses an HTTP 304 status code?
Answers:
a. HttpResponseNotModified
a. HttpResponseRedirect
a. HttpResponseForbidden
a. HttpResponseServerError
19. Which of the following django.template.loader functions will take a list of template names and return the first template that exists?
Answers:
a. find_one_template
a. find_template
a. get_template
a. select_template
20. Which of the following is not a built-in Django template loader class?
Answers:
a. file.Loader
a. cached.Loader
a. eggs.Loader
a. app_directories.Loader
Find out which casino offers poker machines with jackpot
ReplyDeleteand the casino also offers slots, and live 밀양 출장안마 casino table games. A great selection of table games are 경기도 출장안마 available for you 남양주 출장안마 at 포천 출장샵 the casino Rating: 4.1 · 5 reviews 영천 출장안마