Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
d714901a
Commit
d714901a
authored
Jun 27, 2011
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove erronous traceback
parent
d8bec115
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
52 deletions
+48
-52
djangorestframework/views.py
+48
-52
No files found.
djangorestframework/views.py
View file @
d714901a
...
@@ -113,61 +113,57 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
...
@@ -113,61 +113,57 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
# all other authentication is CSRF exempt.
# all other authentication is CSRF exempt.
@csrf_exempt
@csrf_exempt
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
request
=
request
self
.
args
=
args
self
.
kwargs
=
kwargs
self
.
headers
=
{}
# Calls to 'reverse' will not be fully qualified unless we set the scheme/host/port here.
prefix
=
'
%
s://
%
s'
%
(
request
.
is_secure
()
and
'https'
or
'http'
,
request
.
get_host
())
set_script_prefix
(
prefix
)
try
:
try
:
self
.
request
=
request
self
.
initial
(
request
,
*
args
,
**
kwargs
)
self
.
args
=
args
self
.
kwargs
=
kwargs
# Authenticate and check request has the relevant permissions
self
.
headers
=
{}
self
.
_check_permissions
()
# Calls to 'reverse' will not be fully qualified unless we set the scheme/host/port here.
# Get the appropriate handler method
prefix
=
'
%
s://
%
s'
%
(
request
.
is_secure
()
and
'https'
or
'http'
,
request
.
get_host
())
if
self
.
method
.
lower
()
in
self
.
http_method_names
:
set_script_prefix
(
prefix
)
handler
=
getattr
(
self
,
self
.
method
.
lower
(),
self
.
http_method_not_allowed
)
else
:
try
:
handler
=
self
.
http_method_not_allowed
self
.
initial
(
request
,
*
args
,
**
kwargs
)
response_obj
=
handler
(
request
,
*
args
,
**
kwargs
)
# Authenticate and check request has the relevant permissions
self
.
_check_permissions
()
# Allow return value to be either HttpResponse, Response, or an object, or None
if
isinstance
(
response_obj
,
HttpResponse
):
# Get the appropriate handler method
return
response_obj
if
self
.
method
.
lower
()
in
self
.
http_method_names
:
elif
isinstance
(
response_obj
,
Response
):
handler
=
getattr
(
self
,
self
.
method
.
lower
(),
self
.
http_method_not_allowed
)
response
=
response_obj
else
:
elif
response_obj
is
not
None
:
handler
=
self
.
http_method_not_allowed
response
=
Response
(
status
.
HTTP_200_OK
,
response_obj
)
else
:
response_obj
=
handler
(
request
,
*
args
,
**
kwargs
)
response
=
Response
(
status
.
HTTP_204_NO_CONTENT
)
# Allow return value to be either HttpResponse, Response, or an object, or None
# Pre-serialize filtering (eg filter complex objects into natively serializable types)
if
isinstance
(
response_obj
,
HttpResponse
):
response
.
cleaned_content
=
self
.
filter_response
(
response
.
raw_content
)
return
response_obj
elif
isinstance
(
response_obj
,
Response
):
response
=
response_obj
elif
response_obj
is
not
None
:
response
=
Response
(
status
.
HTTP_200_OK
,
response_obj
)
else
:
response
=
Response
(
status
.
HTTP_204_NO_CONTENT
)
# Pre-serialize filtering (eg filter complex objects into natively serializable types)
except
ErrorResponse
,
exc
:
response
.
cleaned_content
=
self
.
filter_response
(
response
.
raw_content
)
response
=
exc
.
response
# Always add these headers.
#
# TODO - this isn't actually the correct way to set the vary header,
# also it's currently sub-obtimal for HTTP caching - need to sort that out.
response
.
headers
[
'Allow'
]
=
', '
.
join
(
self
.
allowed_methods
)
response
.
headers
[
'Vary'
]
=
'Authenticate, Accept'
except
ErrorResponse
,
exc
:
# merge with headers possibly set at some point in the view
response
=
exc
.
response
response
.
headers
.
update
(
self
.
headers
)
# Always add these headers.
return
self
.
render
(
response
)
#
# TODO - this isn't actually the correct way to set the vary header,
# also it's currently sub-obtimal for HTTP caching - need to sort that out.
response
.
headers
[
'Allow'
]
=
', '
.
join
(
self
.
allowed_methods
)
response
.
headers
[
'Vary'
]
=
'Authenticate, Accept'
# merge with headers possibly set at some point in the view
response
.
headers
.
update
(
self
.
headers
)
return
self
.
render
(
response
)
except
:
import
traceback
traceback
.
print_exc
()
raise
class
ModelView
(
View
):
class
ModelView
(
View
):
"""A RESTful view that maps to a model in the database."""
"""A RESTful view that maps to a model in the database."""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment