MCQs > IT & Programming > Django MCQs > Basic Django MCQs

Basic Django MCQ

1. Which is Fictional HTTP request method?

Answer

Correct Answer: PAUSE

Note: This Question is unanswered, help us to find answer for this one

2. Which function in the django.urls package can help you avoid hardcoding URLS by generating a URL given the name of a view?

Answer

Correct Answer: Reverse()

Note: This Question is unanswered, help us to find answer for this one

3. Which is not a third-party package commonly used for authentication?

Answer

Correct Answer: Django-rest-framework-jwt

Note: This Question is unanswered, help us to find answer for this one

4. To add a new app to an existing Django project, you must edit the _ section of the _ file.

Answer

Correct Answer: INSTALLED_APPS; settings.py

Note: This Question is unanswered, help us to find answer for this one

5. What python module might be used to store the current state of a Django model in a file?

Answer

Correct Answer: Pickle

Note: This Question is unanswered, help us to find answer for this one

6. You are uploading a file to Django from a form and you want to save the received file as a field on a model object. You can simply assign the file object from**_to a field of type__**in the model.

Answer

Correct Answer: Request.FILES; FileField

Note: This Question is unanswered, help us to find answer for this one

7. What is a callable that takes a value and raises an error if the value fails to meet some criteria?

Answer

Correct Answer: Validator

Note: This Question is unanswered, help us to find answer for this one

8. When should you employ the POST method over the GET method for submitting data from a form?

Answer

Correct Answer: When the data in the form may be sensitive

Note: This Question is unanswered, help us to find answer for this one

9. In Django, what are used to customize the data that is sent to the templates?

Answer

Correct Answer: Views

Note: This Question is unanswered, help us to find answer for this one

10. Why might you want to write a custom model Manager?

Answer

Correct Answer: To modify the initial QuerySet that the Manager returns

Note: This Question is unanswered, help us to find answer for this one

11. Which statement is most accurate, regarding using the default SQLite database on your local/development machine but Postgres in production

Answer

Correct Answer: There's less chance of introducing bugs since SQLite already works out the box

Note: This Question is unanswered, help us to find answer for this one

12. Which generic view should be used for displaying the tittles of all Django Reinhardt's songs?

Answer

Correct Answer: ListView

Note: This Question is unanswered, help us to find answer for this one

13. What is WSGI?

Answer

Correct Answer: A server

Note: This Question is unanswered, help us to find answer for this one

14. What method can you use to check if form data has changed when using a form instance?

Answer

Correct Answer: Has_changed()

Note: This Question is unanswered, help us to find answer for this one

15. How would you stop Django from performing database table creation or deletion operations via migrations for a particular model?**

Answer

Correct Answer: Set managed=False inside the model.

Note: This Question is unanswered, help us to find answer for this one

16. To expose an existing model via an API endpoint, what do you need to implement?**

Answer

Correct Answer: A serializer

Note: This Question is unanswered, help us to find answer for this one

17. What is the result of this template code? {{"live long and prosper"|truncate:3}}

Answer

Correct Answer: Live long and ...

Note: This Question is unanswered, help us to find answer for this one

18. Which is not part of Django's design philosophy?

Answer

Correct Answer: Implicit over explicit

Note: This Question is unanswered, help us to find answer for this one

19. What do Django best practice suggest should be "fat"?

Answer

Correct Answer: Models

Note: This Question is unanswered, help us to find answer for this one

20. What executes various Django commands such as running a webserver or creating an app?

Answer

Correct Answer: Manage.py

Note: This Question is unanswered, help us to find answer for this one

21. Virtual environments are for managing dependencies. Which granularity works best?

Answer

Correct Answer: You should set up a new virtualenv for each Django project

Note: This Question is unanswered, help us to find answer for this one

22. Which command to access the built-in admin tool for the first time?

Answer

Correct Answer: Python manage.py createsuperuser

Note: This Question is unanswered, help us to find answer for this one

23. Which class allows you to automatically create a Serializer class with fields and validators that correspond to your model's fields?

Answer

Correct Answer: ModelSerializer

Note: This Question is unanswered, help us to find answer for this one

24. Which type of class allows QuerySets and model instances to be converted to native Python data types for use in APIs?

Answer

Correct Answer: Serializers

Note: This Question is unanswered, help us to find answer for this one

25. Which command would you use to apply a migration?

Answer

Correct Answer: Migrate

Note: This Question is unanswered, help us to find answer for this one

26. To secure an API endpoint, making it accessible to registered users only, you can replace the rest_framework.permissions.allowAny value in the default_permissions section of your settings.py to

Answer

Correct Answer: Rest_framework.permissions.IsAuthenticated

Note: This Question is unanswered, help us to find answer for this one

27. What is a callable that takes a value and raises an error if the value fails?

Answer

Correct Answer: Validator

Note: This Question is unanswered, help us to find answer for this one

28. What decorator is used to require that a view accepts only the get and head methods?

Answer

Correct Answer: Require_safe()

Note: This Question is unanswered, help us to find answer for this one

29. Which infrastructure do you need: title=models.charfield(max_length=100, validators=[validate_spelling])

Answer

Correct Answer: A validators file containing a function called validate_spelling imported at the top of model

Note: This Question is unanswered, help us to find answer for this one

30. When to use the Django sites framework?

Answer

Correct Answer: If your single installation powers more than one site

Note: This Question is unanswered, help us to find answer for this one

31. When should you employ the POST method over GET for submitting data?

Answer

Correct Answer: When the data in the form may be sensitive

Note: This Question is unanswered, help us to find answer for this one

32. You should use the http method ___ to read data and ___ to update or create data

Answer

Correct Answer: GET; POST

Note: This Question is unanswered, help us to find answer for this one

33. Which will show the currently installed version?

Answer

Correct Answer: Import django django.get_version()

Note: This Question is unanswered, help us to find answer for this one

34. Which is not a Django filed type for integers?

Answer

Correct Answer: NegativeIntegerField

Note: This Question is unanswered, help us to find answer for this one

35. What does an F() object allow you when dealing with models?

Answer

Correct Answer: Perform db operations without fetching a model object

Note: This Question is unanswered, help us to find answer for this one

36. A project has accumulated 500 migrations. Which course of action would you pursue?

Answer

Correct Answer: Use squashmigrations to reduce the number

Note: This Question is unanswered, help us to find answer for this one

37. Which variable name is best according to PEP 8 guidelines?

Answer

Correct Answer: Number_of_fingers

Note: This Question is unanswered, help us to find answer for this one

38. Django supplies sensible default values for settings. In which Python module can you find these settings?

Answer

Correct Answer: Django.conf.global_settings.py

Note: This Question is unanswered, help us to find answer for this one

39. You have found a bug in Django and you want to submit a patch. Which is the correct procedure?

Answer

Correct Answer: All of these answers.

Note: This Question is unanswered, help us to find answer for this one

40. Which function of Django's Form class will render a form's fields as a series of tags?

Answer

Correct Answer: As_p()

Note: This Question is unanswered, help us to find answer for this one

41. You receive a MultiValueDictKeyError when trying to access a request parameter with the following code: request.GET['search_term']. Which solution will NOT help you in this scenario?

Answer

Correct Answer: Switch to using POST instead of GET as the request method.

Note: This Question is unanswered, help us to find answer for this one

42. Why are QuerySets considered "lazy"?

Answer

Correct Answer: QuerySets do not create any database activity until they are evaluated.

Note: This Question is unanswered, help us to find answer for this one

43. You want to create a page that allows editing of two classes connected by a foreign key (e.g., a question and answer that reside in separate tables). What Django feature can you use?

Answer

Correct Answer: Actions

Note: This Question is unanswered, help us to find answer for this one

44. Should you create a custom user model for new projects?

Answer

Correct Answer: No. Django's built-in models.User class has been tried and tested—no point in reinventing the wheel.

Note: This Question is unanswered, help us to find answer for this one

45. What is the correct way to make a variable available to all of your templates?

Answer

Correct Answer: Use RequestContext.

Note: This Question is unanswered, help us to find answer for this one

46. Which is NOT a valid step in configuring your Django 2.x instance to serve up static files such as images or CSS?

Answer

Correct Answer: In your urls file, add a pattern that includes the name of your static directory.

Note: This Question is unanswered, help us to find answer for this one

47. Which skills do you need to maintain a set of Django templates?

Answer

Correct Answer: HTML and template syntax

Note: This Question is unanswered, help us to find answer for this one

48. Django's class-based generic views provide which classes that implement common web development tasks?

Answer

Correct Answer: Abstract

Note: This Question is unanswered, help us to find answer for this one

49. What is the typical order of an HTTP request/response cycle in Django?

Answer

Correct Answer: URL > view > template

Note: This Question is unanswered, help us to find answer for this one

50. What will this URL pattern match? url(r'^$', views.hello)

Answer

Correct Answer: An empty string at the server root

Note: This Question is unanswered, help us to find answer for this one

51. Which best practice is NOT relevant to migrations?

Answer

Correct Answer: To make sure that your migrations are up to date, you should run updatemigrations before running your tests.

Note: This Question is unanswered, help us to find answer for this one

52. You have inherited a Django project and need to get it running locally. It comes with a requirements.txt file containing all its dependencies. Which command should you use?

Answer

Correct Answer: Pip install -r requirements.txt

Note: This Question is unanswered, help us to find answer for this one

53. What is the correct way to begin a class called "Rainbow" in Python?

Answer

Correct Answer: Class Rainbow:

Note: This Question is unanswered, help us to find answer for this one

54. Every time a user is saved, their quiz_score needs to be recalculated. Where might be an ideal place to add this logic?

Answer

Correct Answer: Model

Note: This Question is unanswered, help us to find answer for this one

55. Which step would NOT help you troubleshoot the error "django-admin: command not found"?

Answer

Correct Answer: Make sure that you have created a Django project.

Note: This Question is unanswered, help us to find answer for this one

56. How do you turn off Django’s automatic HTML escaping for part of a web page?

Answer

Correct Answer: You don't need to do anything—autoescaping is off by default.

Note: This Question is unanswered, help us to find answer for this one

57. How do you determine at startup time if a piece of middleware should be used?

Answer

Correct Answer: Raise MiddlewareNotUsed in the init function of your middleware.

Note: This Question is unanswered, help us to find answer for this one

58. To automatically provide a value for a field, or to do validation that requires access to more than a single field, you should override the ___ method in the ___ class.

Answer

Correct Answer: Clean(); Field

Note: This Question is unanswered, help us to find answer for this one

59. In which programming language is Django written?

Answer

Correct Answer: Python

Note: This Question is unanswered, help us to find answer for this one

60. To cache your entire site for an application in Django, you add all except which of these settings?

Answer

Correct Answer: Django.middleware.cache.AcceleratedCacheMiddleware

Note: This Question is unanswered, help us to find answer for this one

61. A circuit has an output that is determined by the present input as well as the previous output states. The circuit is known as _____.

Answer

Correct Answer: a sequential circuit

Note: This Question is unanswered, help us to find answer for this one

62. Which of the following is not a predefined log level in Django?

Answer

Correct Answer: FATAL

Note: This Question is unanswered, help us to find answer for this one

63.

Which of the following statements are true about the ImageField class?

Note: There may be more than one right answer.


Answer

Correct Answer:

It inherits all attributes and methods from the FileField class.


It validates that the uploaded object is a valid image.


It's default form widget is a ClearableFileInput.


Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

64.

Check all True facts about Django.

Note: There may be more than one right answer.


Answer

Correct Answer:

Written in Python



Web Application Framework



Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

65. What is the best way to extend the Django user model with extra custom fields in addition to the fields already provided?

Answer

Correct Answer: Subclass django.contrib.auth.models.AbstractUser and add the extra fields.

Note: This Question is unanswered, help us to find answer for this one

66. Which of the following statements is true about the django.template.RequestContext class?

Answer

Correct Answer: It takes an HttpRequest as its first argument.

Note: This Question is unanswered, help us to find answer for this one

67.

What is the default max_length value of a SlugField class in Django?

Answer

Correct Answer: 50

Note: This Question is unanswered, help us to find answer for this one

68.

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

Answer

Correct Answer: python manage.py migrate

Note: This Question is unanswered, help us to find answer for this one

69.

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

Answer

Correct Answer: {{object}}

Note: This Question is unanswered, help us to find answer for this one

70.

How do you inherit the A.html template in B.html template?

Answer

Correct Answer: In B template, use {% extends "A.html" %}

Note: This Question is unanswered, help us to find answer for this one

71.

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

Answer

Correct Answer: form.cleaned_data

Note: This Question is unanswered, help us to find answer for this one

72.

Assume a, b, c, d and e are variables which hold some random integer from 1 to 10. Which of the following is NOT correct in django template?

Answer

Correct Answer: {% if a > b > c %}

Note: This Question is unanswered, help us to find answer for this one

73.

Which template command makes a custom template tag/filter available in template?

Answer

Correct Answer: {% load %}

Note: This Question is unanswered, help us to find answer for this one

74.

Which form method binds the data in the URL and is passed to the view?

Answer

Correct Answer: GET

Note: This Question is unanswered, help us to find answer for this one

75.

Which database is not supported by Django ORM?

Answer

Correct Answer: Mongodb

Note: This Question is unanswered, help us to find answer for this one

76.

Django is written in

Answer

Correct Answer: Python

Note: This Question is unanswered, help us to find answer for this one

77.

What is the correct way to randomly order a queryset?

Answer

Correct Answer: order_by('?')

Note: This Question is unanswered, help us to find answer for this one

78.

What is the correct way to Abstract Model class?

Answer

Correct Answer: Add abstract=True in Meta class

Note: This Question is unanswered, help us to find answer for this one

79.

Which of the following is true for model field names?

Answer

Correct Answer: Both of the above

Note: This Question is unanswered, help us to find answer for this one

80.

Which of the following gets called when a view raises an exception?

Answer

Correct Answer: process_exception()

Note: This Question is unanswered, help us to find answer for this one

81.

Which of the following is not a built-in Django template loader class?

Answer

Correct Answer: file.Loader

Note: This Question is unanswered, help us to find answer for this one

82.

Which is the correct way to start a new app inside a django project? [assume new app is called ‘myapp’]

Answer

Correct Answer: python manage.py startapp myapp

Note: This Question is unanswered, help us to find answer for this one

83.

Which of following statements is true to get a Queryset of all Entries which were published before 2006?

Answer

Correct Answer: Entry.objects.get(pub_date__year__in=2006)

Note: This Question is unanswered, help us to find answer for this one

84.

How would you check if a list my_list is empty or not in template ?

Answer

Correct Answer: Both 1 and 2

Note: This Question is unanswered, help us to find answer for this one

85.

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

Answer

Correct Answer: Super users and staff users

Note: This Question is unanswered, help us to find answer for this one

86.

Which query includes a shirt with size 40?

Answer

Correct Answer: Both 2 and 3

Note: This Question is unanswered, help us to find answer for this one

87.

Which of the following are valid built-in signal provided by django? Check all that apply.

Answer

Correct Answer: request_started
m2m_changed

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

88.

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

Answer

Correct Answer: Django-admin.py loaddata

Note: This Question is unanswered, help us to find answer for this one

89.

Which of the following methods are allowed in django Listview? Check all that apply.

Note: There may be more than one right answer.

Answer

Correct Answer: get_context_data
get_queryset
get 

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

90.

What is the table name for model named Choice in application question?

Answer

Correct Answer: question_choice

Note: This Question is unanswered, help us to find answer for this one

91.

What is the exception raised for this query Entry.objects.filter(blog_id=4)?

Answer

Correct Answer: TypeError

Note: This Question is unanswered, help us to find answer for this one

92.

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

Answer

Correct Answer: ObjectDoesNotExist

Note: This Question is unanswered, help us to find answer for this one

93.

Which of the following is NOT correct about Django Models?

Answer

Correct Answer: The name of the table is automatically derived from some model metadata and can not be overridden.

Note: This Question is unanswered, help us to find answer for this one

94.

Which of the following will not register a model "Test" to Django admin?

Answer

Correct Answer: admin(Test)

Note: This Question is unanswered, help us to find answer for this one

95.

Which of the following are built-in signal provided by Django?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

96.

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

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

97.

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

Answer

Correct Answer: models.CharField(max_length=10, blank=True, null=True)

Note: This Question is unanswered, help us to find answer for this one

98.

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

Answer

Correct Answer: Pulls out all the strings marked for translation and makes a message file in the locale directory.

Note: This Question is unanswered, help us to find answer for this one

99.

Which of the following statements is true about the QuerySet select_related() method?

Answer

Correct Answer: Returns a QuerySet that will “follow” foreign-key relationships, selecting additional related-object data when it executes its query.

Note: This Question is unanswered, help us to find answer for this one

100.

Which of the following are determined by Django using field class types?

Answer

Correct Answer: The database column type
The default HTML widget to avail while rendering a form field

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

101.

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

Answer

Correct Answer: url(r'^admin/', include(admin.site.urls))

Note: This Question is unanswered, help us to find answer for this one

102.

What is true about the management command collectstatic?

Answer

Correct 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.

Note: This Question is unanswered, help us to find answer for this one

103.

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

Answer

Correct Answer: manage.py

Note: This Question is unanswered, help us to find answer for this one

104.

Which of the following is not true about testing?

Answer

Correct Answer: The command used to run all unit tests is ./manage.py test --all

Note: This Question is unanswered, help us to find answer for this one

105.

Which command runs all test in a django project?

Answer

Correct Answer: python manage.py test

Note: This Question is unanswered, help us to find answer for this one

106.

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

Answer

Correct Answer: Many to one: Many instances of B can have one instance of A

Note: This Question is unanswered, help us to find answer for this one

107.

Which of the following is not True?

Answer

Correct Answer: Django does not support Unicode data everywhere.

Note: This Question is unanswered, help us to find answer for this one

108.

Which of the following is not a layer in Django?

Answer

Correct Answer: None of the above

Note: This Question is unanswered, help us to find answer for this one

109.

Which of the following classes uses an HTTP 304 status code?

Answer

Correct Answer: HttpResponseNotModified

Note: This Question is unanswered, help us to find answer for this one

110.

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

Answer

Correct Answer: include

Note: This Question is unanswered, help us to find answer for this one

111.

How would you iterate through a list called my_list in template ?

Answer

Correct Answer: {% for x in my_list %} {% endfor %}

Note: This Question is unanswered, help us to find answer for this one

112.

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

Answer

Correct Answer: Dictionary

Note: This Question is unanswered, help us to find answer for this one

113.

Which query gives the count of vehicles that are private?

Answer

Correct Answer: Both 1 and 3

Note: This Question is unanswered, help us to find answer for this one

114.

Which attribute is used to order the objects in django admin?

Answer

Correct Answer: ordering

Note: This Question is unanswered, help us to find answer for this one

115.

Which of the following methods is not used in django ListView?

Answer

Correct Answer: get_object

Note: This Question is unanswered, help us to find answer for this one

116.

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

Answer

Correct Answer: python manage.py createsuperuser

Note: This Question is unanswered, help us to find answer for this one

117.

Which decorators are used to restrict authentication of users?

Note: There may be more than one right answer.

Answer

Correct Answer: @permission_required
@user_passes_test
@login_required 

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

118.

Which of the following is true about generators?

Answer

Correct Answer: Generators must contain a yield statement

Note: This Question is unanswered, help us to find answer for this one

119.

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

Answer

Correct Answer: Ansible

Note: This Question is unanswered, help us to find answer for this one

120.

What is the full form of FBV and CBV?

Answer

Correct Answer: Function Based Views & Class Based Views

Note: This Question is unanswered, help us to find answer for this one

121.

Which of the following caching strategies are supported in Django? (check any that apply)

Note: There may be more than one right answer.

Answer

Correct Answer: File sytem caching
In-memory caching 

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

122.

Which of the following caching strategies can be implemented in Django?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

123.

Which of the following is the correct way to specify a translation string?

Answer

Correct Answer: Both of the above

Note: This Question is unanswered, help us to find answer for this one

124.

Which of the following features are supported by Django?

Answer

Correct Answer: All of the above 

Note: This Question is unanswered, help us to find answer for this one

125.

What is the exception raised when a duplicate value is used in unique field while inserting a record?

Answer

Correct Answer: IntegrityError

Note: This Question is unanswered, help us to find answer for this one

126.

Which is the correct way to allow empty value in Integer Field?

Answer

Correct Answer: models.IntegerField(blank=True, null=True)

Note: This Question is unanswered, help us to find answer for this one

127.

How can you set up static files in Django?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

128.

Django is a web __ in Python to develop a web application.

Answer

Correct Answer: Framework

Note: This Question is unanswered, help us to find answer for this one

129.

What does setting SESSION_COOKIE_SECURE = True do?

Answer

Correct Answer: Ensures cookie can be sent on HTTPS connection only

Note: This Question is unanswered, help us to find answer for this one

130.

Which of the following are correct ways to add a message?

Answer

Correct Answer: messages.add_message(request, messages.INFO, 'Hello world.')
messages.info(request, 'Hello world.')
messages.success(request, 'Hello world.') 

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

131.

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

Answer

Correct Answer: The app that contain the template tag is not in INSTALLED_APPS

Note: This Question is unanswered, help us to find answer for this one

132.

Which Django core function can be used to send an email?

Answer

Correct Answer: django.core.mail.send_mail

Note: This Question is unanswered, help us to find answer for this one

133.

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

Answer

Correct Answer: form action="" method="post">{% csrf_token %}

Note: This Question is unanswered, help us to find answer for this one

134.

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

Correct Answer: No exception will be raised

Note: This Question is unanswered, help us to find answer for this one

135.

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

Answer

Correct Answer: Either 1 or 2

Note: This Question is unanswered, help us to find answer for this one

136.

Which of the following is NOT used to represent ManyToManyField in django model form? Check all that apply.

Note: There may be more than one right answer.

Answer

Correct Answer: Charfield
ModelChoiceField

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

137.

How is the ManyToManyField represented in Django model form?

Answer

Correct Answer: ModelMultipleChoiceField

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: apnumber

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: @sensitive_variables

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: Y/m/d g:i:s A

Note: This Question is unanswered, help us to find answer for this one

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

Answer

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

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: LargeIntegerField

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: Model.objects.using('other').all()

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: User.objects.filter( name__iregex=r'^(fred|bob).+' )

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: Using META ordering attribute

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: simple_tag

Note: This Question is unanswered, help us to find answer for this one

148. 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 %}

Answer

Correct Answer: {{ block.super }}

Note: This Question is unanswered, help us to find answer for this one

149. The django.contrib.contenttypes application provides

Answer

Correct Answer: a generic interface for working with models

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: Jacob Kaplan-Moss and Adrian Holovaty

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: getattr(settings, "SETTING_NAME", default_value)

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: django.db.models.fields.files.ImageField

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: models.ForeignKey('self')

Note: This Question is unanswered, help us to find answer for this one

154. 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?

Answer

Correct Answer: form.clean

Note: This Question is unanswered, help us to find answer for this one

155. In settings.py, when DEBUG is set to ________, Django will email unhandled exceptional conditions.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: ./manage.py sql myapp

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: list_display

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: Raise ValidationError in MyForm.clean()

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: prefix

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: created = models.DateTimeField(auto_now_add=True)

Note: This Question is unanswered, help us to find answer for this one

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

Answer

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

Note: This Question is unanswered, help us to find answer for this one

162. 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?

Answer

Correct Answer: clean_foo

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: clean_foo

Note: This Question is unanswered, help us to find answer for this one

164. What command compile Django's translation files?

Answer

Correct Answer: ./manage.py compilemessages

Note: This Question is unanswered, help us to find answer for this one

165. 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'?

Answer

Correct Answer: User.objects.filter( email__iexact='fred@aol.com' )

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: manage.py inspectdb

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: User.objects.filter( last_login__isnull=True )

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: User.objects.all().aggregate( Avg( 'widgets' ) )

Note: This Question is unanswered, help us to find answer for this one

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

Answer

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

Note: This Question is unanswered, help us to find answer for this one

170. What is the purpose of the STATIC_ROOT setting?

Answer

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

Note: This Question is unanswered, help us to find answer for this one

171. 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('', ______________________ )

Answer

Correct Answer: url(r'^admin/', include(admin.site.urls) ),

Note: This Question is unanswered, help us to find answer for this one

172. What does the Django command `manage.py validate` do?

Answer

Correct Answer: Checks for errors in your models.

Note: This Question is unanswered, help us to find answer for this one

173. What is Dijit?

Answer

Correct Answer: Dijit is Dojo’s UI Library.

Note: This Question is unanswered, help us to find answer for this one

174. Where is pre_save signal in Django

Answer

Correct Answer: from django.db.models.signals import pre_save

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: class Meta:

Note: This Question is unanswered, help us to find answer for this one

176. What does the Django command `manage.py shell` do?

Answer

Correct Answer: Starts a Python command prompt with your Django environment pre-loaded.

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: django.contrib

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: User.objects.all()

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: django-admin.py startproject myproject

Note: This Question is unanswered, help us to find answer for this one

180. How to make django timezone-aware?

Answer

Correct Answer: In settings.py: USE_TZ=True

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: The MyObject.DoesNotExist exception is raised.

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: admin.site.register( User )

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: user = models.ForeignKey(User)

Note: This Question is unanswered, help us to find answer for this one

184. What is ModelForm used for?

Answer

Correct Answer: To define a form based on an existing model

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: Use the exclude parameter in the Meta class in your form

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: __unicode__

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: name = models.CharField(max_length=255)

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: mod_wsgi

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: manage.py startapp users

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: In settings.py, add the new app to the INSTALLED_APPS variable.

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: manage.py runserver 12.34.56.78:8080

Note: This Question is unanswered, help us to find answer for this one

192. What does a urls.py file do in Django?

Answer

Correct Answer: It contains URL matching patterns and their corresponding view methods.

Note: This Question is unanswered, help us to find answer for this one

193. Django is written using what programming language?

Answer

Correct Answer: Python

Note: This Question is unanswered, help us to find answer for this one

194. What is the purpose of settings.py?

Answer

Correct Answer: To configure settings for the Django project

Note: This Question is unanswered, help us to find answer for this one

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

Answer

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

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: (r'^pattern/$', YourView.as_view()),

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: render_to_response

Note: This Question is unanswered, help us to find answer for this one

198. What is the definition of a Django Project?

Answer

Correct Answer: A collection of configuration files and individual apps that form a web site.

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: manage.py runserver

Note: This Question is unanswered, help us to find answer for this one