Django 2015

1. What is the command to start Django's built-in development server?
Answers:
• manage.py startserver --dev
• manage.py --run
• manage.py run
• manage.py runserver
• manage.py --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?
Answers:
• 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?
Answers:
• 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?
Answers:
• 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?
Answers:
• In settings.py: USE_L10N=True
• in views.py, import timezone
• In settings.py: USE_TZ=True
• in urls.py, import timezone
• in views.py, 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?
Answers:
• 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'?
Answers:
• django.py startproject myproject
• django-admin.py --start myproject
• django-admin.py startproject myproject
• django.py --new myproject
• django.py new myproject
8. What does the Django command `manage.py shell` do?
Answers:
• 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?
Answers:
• 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?
Answers:
• __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?
Answers:
• user.site.register( Admin )
• admin.register( Users )
• admin.site.register( User )
• admin.site( self, User )
• users.site.register( Admin )
12. What is the most easiest, fastest, and most stable deployment choice in most cases with Django?
Answers:
• AJP
• mod_wsgi
• FastCGI
• SCGI
13. How do you exclude a specific field from a ModelForm?
Answers:
• 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?
Answers:
• django.ponies
• django.utilities
• django.helpers
• django.extras
• django.contrib
15. What is the purpose of settings.py?
Answers:
• 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?
Answers:
• 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?
Answers:
• 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?
Answers:
• (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?
Answers:
• manage.py startapp users
• manage.py start users
• manage.py --startapp users
• manage.py --newapp users
• manage.py newapp users
20. What is the command to run Django's development server on port 8080 on IP address 12.34.56.78?
Answers:
• manage.py --run 12.34.56.78 8080
• manage.py run 12.34.56.78:8080
• manage.py --dev 12.34.56.78:8080
• manage.py runserver 12.34.56.78:8000
• manage.py runserver 12.34.56.78:8080
21. What does a urls.py file do in Django?
Answers:
• 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?
Answers:
• 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?
Answers:
• Run the `manage.py syncdb` command.
• No additional action is required, Django notices new apps automatically.
• Run the `manage.py validate` command, and then start a new shell.
• In settings.py, add the app to the PROJECT_APPS variable.
• In settings.py, add the new app to the INSTALLED_APPS variable.
24. Django is written using what programming language?
Answers:
• Java
• PHP
• Ruby
• Python
• Javascript
25. What is the Django shortcut method to more easily render an html response?
Answers:
• render_to_response
• response_render
• render
• render_to_html
26. What does the Django command `manage.py validate` do?
Answers:
• Checks for errors in your views.
• Checks for errors in your templates.
• Checks for errors in your settings.py 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?
Answers:
• {{ 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?
Answers:
• django-admin.py inspect
• manage.py legacydb
• django-admin.py schemadump
• manage.py inspectdb
• manage.py 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('',     ______________________ )
Answers:
• url(r'^admin/', include(admin.site.urls) ),
• 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?
Answers:
• 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?
Answers:
• 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?
Answers:
• 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?
Answers:
• 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 'fred@aol.com'?
Answers:
• User.objects.filter( email__icontains='fred@aol.com' )
• User.objects.filter( email__exact='fred@aol.com' )
• User.objects.filter( email__iexact='fred@aol.com' )
• User.objects.filter( email__matches='fred@aol.com' )
• User.objects.filter( email__contains='fred@aol.com' )
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?
Answers:
• 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?
Answers:
• 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?
Answers:
• 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 settings.py, when DEBUG is set to ________, Django will email unhandled exceptional conditions.
Answers:
• 1
• Never
• True
• False
• Always
39. How do you create a recursive relationship in a model class named 'Company' in Django?
Answers:
• 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?
Answers:
• 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?
Answers:
• django-admin.py dumpdata myapp
• ./manage.py schema myapp
• ./manage.py sql myapp
• ./manage.py showschema myapp
• ./manage.py showsql myapp
42. What command do you use to alter the fields Django displays for a given model in the Django admin ListView?
Answers:
• 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?
Answers:
• 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:
Answers:
• 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?
Answers:
• 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?
Answers:
• 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 %}
Answers:
• {{ block.super }}
• {% super %}
• {% block.super %}
• super (block, self)__init__()
• {{ extends block }}
48. Which type of custom template tag returns a string?
Answers:
• 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.
Answers:
• False
• True
50. How would you perform a lookup on a model against a database aside from the default?
Answers:
• 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?
Answers:
• 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'?
Answers:
• 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?
Answers:
• 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  ?
Answers:
• 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.
Answers:
• naturaltime
• intcomma
• ordinal
• intword
• apnumber
56. What is the name of the Django decorator that hides sensitive info from error reports?
Answers:
• @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?
Answers:
• created = models.DateTimeField(auto_now=True)
• created = models.DateTimeField(default=datetime.datetime.now())
• 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
Answers:
• 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
Answers:
• 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?
Answers:
• ./manage.py i18n_update
• ./manage.py compiletranslation
• ./manage.py compilei18n
• ./manage.py compilemessages
• ./manage.py 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
Answers:
• Using META order attribute
• Using META ordering attribute
• Using META default_order attribute
• Using META default_order_by attribute

• Using META order_by attribute

No comments:

Post a Comment