Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python decorators can be used in Django in order to avoid duplication of code in view functions. For instance, consider the following definition of a

image text in transcribed

Python decorators can be used in Django in order to avoid duplication of code in view functions. For instance, consider the following definition of a decorator that is then applied to a view function. This code has three bugs: 01: def fetch_author(view_func) : 02: def wrapper(request, *args, kwargs): 03: try: 04: author = Author.objects.get (id=request.GET ["author_id"]) 05: view_func (request, author, *args, **kwargs) 06: except Author.DoesNotExist: 07: return bad_request(request, Author.DoesNotExist) 08: return view_func 09: 10: @fetch_author 11: def books_new(request) : 12: books = Book. objects.filter(authors_in= [author], year_gte="2015") 13: context ={ 14: "title" : "New books", 15: "books" : books, 3 return render (request, "books-recent.html", context) Identify the three lines which contain the three bugs: Line 02 Line 05 Line 08 Line 11 Line 12 Line 17

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql All In One For Dummies 7 Books In One

Authors: Allen G Taylor ,Richard Blum

4th Edition

1394242298, 978-1394242290

More Books

Students also viewed these Databases questions

Question

e. What are notable achievements of the group?

Answered: 1 week ago