Debian Codegraph @

django/views/decorators/common.py

raw
1 from functools import wraps
2
3 from asgiref.sync import iscoroutinefunction
4
5
6 def no_append_slash(view_func):
7 """
8 Mark a view function as excluded from CommonMiddleware's APPEND_SLASH
9 redirection.
10 """
11
12 # view_func.should_append_slash = False would also work, but decorators are
13 # nicer if they don't have side effects, so return a new function.
14
15 if iscoroutinefunction(view_func):
16
17 async def _view_wrapper(request, *args, **kwargs):
18 return await view_func(request, *args, **kwargs)
19
20 else:
21
22 def _view_wrapper(request, *args, **kwargs):
23 return view_func(request, *args, **kwargs)
24
25 _view_wrapper.should_append_slash = False
26
27 return wraps(view_func)(_view_wrapper)