Python | Django Views | Class Based Views

Last Updated :
Discuss
Comments

Question 1

What makes class-based generic views useful for common tasks?

  • They speed up templates only.

  • They write all code for you.

  • They reuse code for list, detail, or forms.

  • They only work with databases.

Question 2

What class do most generic views inherit from to handle requests?

  • ModelView

  • FormView

  • TemplateView

  • View

Question 3

n CreateView, what sets the model to use for new items?

  • template_name = 'create.html'

  • form_class = MyForm

  • model = Post

  • fields = ['title']

Question 4

After saving in CreateView, where does it go by default?

  • Stays on a blank page

  • To the home page

  • Back to the create page

  • To the new item's detail page

Question 5

In ListView, what shows all items from a model?

  • pk = 1

  • form = PostForm()

  • object_list = ['item']

  • queryset = Post.objects.all()

Question 6

What adds pages to ListView for many items?

  • paginate_by = 5

  • page = request.GET['page']

  • order_by('-date')

  • filter(active=True)

Question 7

In DetailView, what gets one item by ID?

  • all().get()

  • filter().first()

  • create()

  • get_object()

Question 8

What template does DetailView look for with model=Post?

  • list.html

  • detail.html

  • post_detail.html

  • form.html

Question 9

In UpdateView, how does the form show old data on load?

  • New form each time

  • instance = get_object()

  • From POST only

  • From list queryset

Question 10

What happens if UpdateView form is valid on POST?

  • Creates a new one

  • Shows list instead

  • Saves changes to the item

  • Deletes it

Tags:

There are 15 questions to complete.

Take a part in the ongoing discussion