0% found this document useful (0 votes)
17 views5 pages

AEX03

Uploaded by

feiers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

AEX03

Uploaded by

feiers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Django Exam 2 Winter 2024

Name: ___________________________________________________________

This exam is closed book, no internet, one page of notes front and back. You can neither give not receive any
assistance to anyone on this exam. The multiple choice questions are five points and the short essay questions
are worth 10 points. There is an extra question so you can miss a question and still get 100%. If you feel a
question is vague or unclear or mistaken, write any assumptions you like about the question and then answer
the question as best as you can. You can put your name on your single page of notes and turn it in with your
exam for grading. Depending on how "good" your notes are, we may award points to cover all or part of any
points you lose on the exam. In no case will your score on this exam be above 100%.

1. For the following line in a views.py file

class ArticleListView(ListView):

what is the best description of "ListView"?

The first parameter to the render() method


The class that is being extended
The name of a view function
The class that is being created
2. In the class django.views.generic.list.ListView, which of the following methods is called earliest in the
process?

get_template_names()
render_to_response()
get_queryset()
get_context_data()
3. For the following line in a views.py file

class ArticleListView(ListView):

what is the best description of "ArticleListView"?

The name of a view function


The class that is being extended
The class that is being created
The first parameter to the render() method
4. There is no way the end use can see the actual data stored in a password form field

True False

5. If you want to override the template name chosen by convention in a View that extends
django.views.generic.detail.DetailView what is the name of the class attribute variable that you use?

template
template_extend
template_override
template_name
6. Which of the following Python types is most like the request.POST data in Django?

dictionary
string
tuple
list
7. What built-in Django template filter capitalizes the first character of the value?

toUCFirst
toupper
capfirst
ucfirst
8. What does the built-in Django template tag "url" do?

Checks if the provided string is a valid url


Encodes the provided string using the url encoding rules
Emits an anchor (a) tag in the HTML
Returns an absolute path reference matching a given view and optional parameters
9. What Django class does a class-based view need to extend to indicate that the view can only be
accessed by logged in users?

AutoLoginView
LoginRequiredMixin
AutoRedirectView
MustLoginView
10. By convention when using an app_name of "abc" and a model of "Dog", if you use a View that extends
django.views.generic.list.ListView, what is the name of the context variable that will include all the Dog
objects in the template when it is being rendered?

dogs.values()
dogs_select
dog_list
dogs
11. You are using the following code in your views.py:

class AutoDelete(LoginRequiredMixin, DeleteView):


model = Auto
fields = '__all__'
success_url = reverse_lazy('autos:all')

There is no get(): method in your class and yet when you send an HTTP GET to the url that is routed to
this view it works fine. Where would you find the definition of the get() method that is being used to
respond to the HTTP GET request?

12. In your make_confirm_delete.html template, you have the following line:

{% extends 'base_bootstrap.html' %}

How does this line affect the HTML that is generated from this template?
13. In your urls.py file, you see the following line.

path('main/<int:pk>/update/', views AutoUpdate.as_view(), name='auto_update'),

What will you see in place of the <int:pk> when looking at an actual URL in the browser when it is
accessing your view?

14. In the following code from your views.py,

class MakeView(LoginRequiredMixin,View) :
def get(self, request):
ml = Make.objects.all();
ctx = { 'make_list': ml };
return render(request, 'autos/make_list.html', ctx)

when is the get method called and what does the get method return to its caller?
15. Your application is experiencing a traceback error on the success_url, line in the following code from
your views.py.

class AutoDelete(LoginRequiredMixin, DeleteView):


model = Auto
fields = '__all__'
success_url = reverse_lazy('autos:all')

What other file in your application should you check to figure out why the reverse_lazy is failing. What
two things should you check in that file?

16. In the following code from your views.py,

class MakeView(LoginRequiredMixin,View) :
def get(self, request):
ml = Make.objects.all();
ctx = { 'make_list': ml };
return render(request, 'autos/make_list.html', ctx)

what is the purpose of the ctx variable?

You might also like