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:
Answers:
Answers:
Answers:
Which of the following code snippets is the most performant when concatenating the two QuerySets into one list?
Answers:
Answers:
class Salary(models.Model):
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:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
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:
- date_object = time.strptime(dt, ‘%b %d %Y %I:%M%p’)
- date_object = datetime.strptime(dt, ‘%b %d %Y %I:%M%p’)
- date_object = datetime.strptime(dt, ‘%B %D %Y %I:%M%p’)
- date_object = time.strptime(dt, ‘%b %d %Y %I:%M%p’)
Answers:
- It is used when performing a query, or as a part of a URL, since by default it ensures uniqueness.
- To create a slug based on another field automatically in the admin, prepopulated_fields has to be used.
- It can only contain letters, numbers, underscores or hyphens.
- Slugs can created in Django templates using the builtin filter, “django.template.defaultfilters.slugify”, formatted as {{ some_text|slugify }}.
Answers:
- It takes a path and urljoins it with the static prefix STATIC_URL.
- It adds STATIC_URL to every template context rendered with RequestContext contexts.
- It populates a template variable with the static prefix STATIC_URL to be used as a variable or directly.
- None of these.
Answers:
- 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 of the following code snippets is the most performant when concatenating the two QuerySets into one list?
Answers:
- from itertools import chain result_list = list(chain(query_set_1,query_set_2))
- result_list = query_set_1 | query_set_2
- from django.db.models import Q result_list = Q(query_set_1) | Q(query_set_1)
- from itertools import chain result_list = chain(query_set_1, query_set_2)
Answers:
- “atomic” blocks allows the creation of blocks of code within which the atomicity on the database is guaranteed.
- “atomic” blocks cannot be nested.
- “atomic” can be used as a decorator.
- “atomic” can be used as a context manager.
class Salary(models.Model):
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:
- results = Salary.objects.exclude(retired=true, amount__lt=7300).exclude(retired=true,amount__gt=7300)
- from django.db.models import Q results = Salary.filter(~Q(amount=7300),retired=True)
- results = Salary.objects.filtered(retired=True, amount__ne=7300)
- from django.db.models import Q results = Salary.filter(Q(amount=7300),retired=True)
Answers:
- view_exception()
- process_exception()
- execution_exception()
- controller_exception()
Answers:
- Use a a proxy model based on django.contrib.auth.models.User.
- Subclass django.contrib.auth.models.AbstractUser and add the extra fields.
- Subclass django.contrib.auth.models.AbstractBaseUser and add the extra fields.
- Use a one-to-one relationship to a model containing the extra fields.
Answers:
- It inherits all attributes and methods from the FileField class.
- It validates that the uploaded object is a valid image.
- Its instances are created as varchar(200) columns in the database.
- It’s default form widget is a ClearableFileInput.
Answers:
- It adds its argument to the value.
- It caches a complex under a simpler name.
- It filters the contents of the blog through one or more filters.
- None of these.
Answers:
- If DEBUG = False and ALLOWED_HOSTS= [] the method will raise SuspiciousOperation exception resulting in an HTTP Error 500 Internal server error.
- 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.
- 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.
- 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.
Answers:
- 50
- 100
- 25
- 150
Answers:
- AppCommand
- HelperCommand
- HandlerCommand
- DBCommand
Answers:
- Django stores passwords in plain text on the user model.
- It returns a UserAccount object is the password for a given username is authenticated.
- Permissions can only be set on a per type of object basis.
- django.contrib.auth will ensure that add, change and delete permissions are created for each Django model defined in an installed application.
Answers:
- The template response will be applied.
- The response middleware will be applied.
- The default exception handling will be applied.
- None of these.
Answers:
- DEBUG
- INFO
- WARNING
- FATAL
Answers:
- HttpResponseNotModified
- HttpResponseRedirect
- HttpResponseForbidden
- HttpResponseServerError
Answers:
- find_one_template
- find_template
- get_template
- select_template
Answers:
- file.Loader
- cached.Loader
- eggs.Loader
- app_directories.Loader
No comments:
Post a Comment