2014-04-22 20:19:46 +00:00
|
|
|
from functools import partial, update_wrapper
|
|
|
|
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.contrib.auth.decorators import user_passes_test
|
2010-08-14 14:27:35 +00:00
|
|
|
from django.http import HttpResponse
|
2015-12-30 15:51:16 +00:00
|
|
|
from django.urls import reverse_lazy
|
2024-10-17 15:59:58 +00:00
|
|
|
from django.views.generic import RedirectView, View
|
2010-08-14 14:27:35 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-08-31 11:11:20 +00:00
|
|
|
def empty_view(request, *args, **kwargs):
|
2019-02-09 21:27:32 +00:00
|
|
|
return HttpResponse()
|
2008-09-27 06:14:11 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-09-27 06:14:11 +00:00
|
|
|
def absolute_kwargs_view(request, arg1=1, arg2=2):
|
2019-02-09 21:27:32 +00:00
|
|
|
return HttpResponse()
|
2010-08-06 13:47:56 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-05-07 16:59:25 +00:00
|
|
|
def defaults_view(request, arg1, arg2):
|
|
|
|
pass
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2014-04-20 17:12:43 +00:00
|
|
|
def nested_view(request):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2011-06-16 16:41:14 +00:00
|
|
|
def erroneous_view(request):
|
2013-10-18 11:25:30 +00:00
|
|
|
import non_existent # NOQA
|
2011-06-16 16:41:14 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-09-27 13:06:58 +00:00
|
|
|
def pass_resolver_match_view(request, *args, **kwargs):
|
2019-02-09 21:27:32 +00:00
|
|
|
response = HttpResponse()
|
2012-09-27 13:06:58 +00:00
|
|
|
response.resolver_match = request.resolver_match
|
|
|
|
return response
|
|
|
|
|
2016-11-12 17:11:23 +00:00
|
|
|
|
2015-04-24 19:51:26 +00:00
|
|
|
uncallable = None # neither a callable nor a string
|
2011-06-16 16:41:14 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2017-01-19 07:39:46 +00:00
|
|
|
class ViewClass:
|
2010-08-06 13:47:56 +00:00
|
|
|
def __call__(self, request, *args, **kwargs):
|
2019-02-09 21:27:32 +00:00
|
|
|
return HttpResponse()
|
2010-08-06 13:47:56 +00:00
|
|
|
|
2016-11-12 17:11:23 +00:00
|
|
|
|
2010-08-06 13:47:56 +00:00
|
|
|
view_class_instance = ViewClass()
|
2010-08-14 14:27:35 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-05-12 13:24:07 +00:00
|
|
|
class LazyRedirectView(RedirectView):
|
2011-04-29 11:49:59 +00:00
|
|
|
url = reverse_lazy("named-lazy-url-redirected-to")
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2016-04-02 11:18:26 +00:00
|
|
|
@user_passes_test(
|
|
|
|
lambda u: u.is_authenticated, login_url=reverse_lazy("some-login-page")
|
2022-02-03 19:24:19 +00:00
|
|
|
)
|
2011-04-29 11:49:59 +00:00
|
|
|
def login_required_view(request):
|
|
|
|
return HttpResponse("Hello you")
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2010-08-14 14:27:35 +00:00
|
|
|
def bad_view(request, *args, **kwargs):
|
|
|
|
raise ValueError("I don't think I'm getting good value for this view")
|
2014-04-22 20:19:46 +00:00
|
|
|
|
|
|
|
|
2024-10-22 12:12:02 +00:00
|
|
|
class HelloView(View):
|
2024-10-17 15:59:58 +00:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
return HttpResponse(f"Hello {self.kwargs['name']}")
|
|
|
|
|
|
|
|
|
2024-10-22 12:12:02 +00:00
|
|
|
view_func_from_cbv = HelloView.as_view()
|
2024-10-17 15:59:58 +00:00
|
|
|
|
2014-04-22 20:19:46 +00:00
|
|
|
empty_view_partial = partial(empty_view, template_name="template.html")
|
2016-01-05 21:47:48 +00:00
|
|
|
empty_view_nested_partial = partial(
|
|
|
|
empty_view_partial, template_name="nested_partial.html"
|
|
|
|
)
|
2014-04-22 20:19:46 +00:00
|
|
|
empty_view_wrapped = update_wrapper(
|
|
|
|
partial(empty_view, template_name="template.html"),
|
|
|
|
empty_view,
|
|
|
|
)
|