Opened 6 years ago

Last modified 6 years ago

#29664 closed Cleanup/optimization

Need Proper error handling for CBV in urls. — at Version 1

Reported by: Amar Owned by: emiamar@…
Component: Core (URLs) Version: 2.1
Severity: Normal Keywords:
Cc: emiamar@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Amar)

When in urls.py if one misses to call as_view() (Example shown below) method django throws weird error. Need better way of handling error

Incorrect definition

urlpatterns = [
    path('admin/', admin.site.urls),
    path('hello/', HelloView)
]

Correct definition

urlpatterns = [
    path('admin/', admin.site.urls),
    path('hello/', HelloView.as_view())
]

Error

TypeError at /hello/

__init__() takes 1 positional argument but 2 were given

Request Method: 	GET
Request URL: 	http://localhost:8000/hello/
Django Version: 	2.0.7
Exception Type: 	TypeError
Exception Value: 	

__init__() takes 1 positional argument but 2 were given

Exception Location: 	/home/amar/.virtualenvs/djmongo/lib/python3.6/site-packages/django/core/handlers/base.py in _get_response, line 126

This make it really hard to figure out actual error. I faced this once and had to struggle for hours to understand what went wrong. Here is my PR

Change History (1)

comment:1 by Amar, 6 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top