当前位置: 首页>>代码示例>>Python>>正文


Python TemplateView.as_view方法代码示例

本文整理汇总了Python中django.views.generic.TemplateView.as_view方法的典型用法代码示例。如果您正苦于以下问题:Python TemplateView.as_view方法的具体用法?Python TemplateView.as_view怎么用?Python TemplateView.as_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.views.generic.TemplateView的用法示例。


在下文中一共展示了TemplateView.as_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: config_error_view

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def config_error_view(request: HttpRequest, error_category_name: str) -> HttpResponse:
    contexts = {
        'apple': {'social_backend_name': 'apple', 'has_markdown_file': True},
        'google': {'social_backend_name': 'google', 'has_markdown_file': True},
        'github': {'social_backend_name': 'github', 'has_markdown_file': True},
        'gitlab': {'social_backend_name': 'gitlab', 'has_markdown_file': True},
        'ldap': {'error_name': 'ldap_error_realm_is_none'},
        'dev': {'error_name': 'dev_not_supported_error'},
        'saml': {'social_backend_name': 'saml'},
        'smtp': {'error_name': 'smtp_error'},
        'backend_disabled': {'error_name': 'remoteuser_error_backend_disabled'},
        'remote_user_header_missing': {'error_name': 'remoteuser_error_remote_user_header_missing'},
    }

    return TemplateView.as_view(template_name='zerver/config_error.html',
                                extra_context=contexts[error_category_name])(request) 
开发者ID:zulip,项目名称:zulip,代码行数:18,代码来源:auth.py

示例2: test_invalid_keyword_argument

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def test_invalid_keyword_argument(self):
        """
        View arguments must be predefined on the class and can't
        be named like a HTTP method.
        """
        msg = (
            "You tried to pass in the %s method name as a keyword argument "
            "to SimpleView(). Don't do that."
        )
        # Check each of the allowed method names
        for method in SimpleView.http_method_names:
            with self.assertRaisesMessage(TypeError, msg % method):
                SimpleView.as_view(**{method: 'value'})

        # Check the case view argument is ok if predefined on the class...
        CustomizableView.as_view(parameter="value")
        # ...but raises errors otherwise.
        msg = (
            "CustomizableView() received an invalid keyword 'foobar'. "
            "as_view only accepts arguments that are already attributes of "
            "the class."
        )
        with self.assertRaisesMessage(TypeError, msg):
            CustomizableView.as_view(foobar="value") 
开发者ID:nesdis,项目名称:djongo,代码行数:26,代码来源:test_base.py

示例3: start_two_factor_auth

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def start_two_factor_auth(request: HttpRequest,
                          extra_context: ExtraContext=None,
                          **kwargs: Any) -> HttpResponse:
    two_fa_form_field = 'two_factor_login_view-current_step'
    if two_fa_form_field not in request.POST:
        # Here we inject the 2FA step in the request context if it's missing to
        # force the user to go to the first step of 2FA authentication process.
        # This seems a bit hackish but simplifies things from testing point of
        # view. I don't think this can result in anything bad because all the
        # authentication logic runs after the auth step.
        #
        # If we don't do this, we will have to modify a lot of auth tests to
        # insert this variable in the request.
        request.POST = request.POST.copy()
        request.POST.update({two_fa_form_field: 'auth'})

    """
    This is how Django implements as_view(), so extra_context will be passed
    to the __init__ method of TwoFactorLoginView.

    def as_view(cls, **initkwargs):
        def view(request, *args, **kwargs):
            self = cls(**initkwargs)
            ...

        return view
    """
    two_fa_view = TwoFactorLoginView.as_view(extra_context=extra_context,
                                             **kwargs)
    return two_fa_view(request, **kwargs) 
开发者ID:zulip,项目名称:zulip,代码行数:32,代码来源:auth.py

示例4: password_reset

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def password_reset(request: HttpRequest) -> HttpResponse:
    if not Realm.objects.filter(string_id=get_subdomain(request)).exists():
        # If trying to get to password reset on a subdomain that
        # doesn't exist, just go to find_account.
        redirect_url = reverse('zerver.views.registration.find_account')
        return HttpResponseRedirect(redirect_url)

    view_func = DjangoPasswordResetView.as_view(template_name='zerver/reset.html',
                                                form_class=ZulipPasswordResetForm,
                                                success_url='/accounts/password/reset/done/')
    return view_func(request) 
开发者ID:zulip,项目名称:zulip,代码行数:13,代码来源:auth.py

示例5: get_urls

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def get_urls(self):
        custom_urls = []
        if self.djangoql_completion:
            custom_urls += [
                url(
                    r'^introspect/$',
                    self.admin_site.admin_view(self.introspect),
                    name='%s_%s_djangoql_introspect' % (
                        self.model._meta.app_label,
                        self.model._meta.model_name,
                    ),
                ),
                url(
                    r'^suggestions/$',
                    self.admin_site.admin_view(self.suggestions),
                    name='%s_%s_djangoql_suggestions' % (
                        self.model._meta.app_label,
                        self.model._meta.model_name,
                    ),
                ),
                url(
                    r'^djangoql-syntax/$',
                    self.admin_site.admin_view(TemplateView.as_view(
                        template_name=self.djangoql_syntax_help_template,
                    )),
                    name='djangoql_syntax_help',
                ),
            ]
        return custom_urls + super(DjangoQLSearchMixin, self).get_urls() 
开发者ID:ivelum,项目名称:djangoql,代码行数:31,代码来源:admin.py

示例6: suggestions

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def suggestions(self, request):
        view = SuggestionsAPIView.as_view(
            schema=self.djangoql_schema(self.model),
        )
        return view(request) 
开发者ID:ivelum,项目名称:djangoql,代码行数:7,代码来源:admin.py

示例7: redirect

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def redirect(url: str):
    return RedirectView.as_view(url=url) 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:4,代码来源:urls.py

示例8: template

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def template(templateName):
  """
  Simple shortcut for indicating in a Django routing file that a template
  should be rendered.
  """
  return TemplateView.as_view(template_name=templateName) 
开发者ID:Polychart,项目名称:builder,代码行数:8,代码来源:utils.py

示例9: permanentRedirect

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def permanentRedirect(targetUrl):
  """
  Simple shortcut for indicating a 301 redirect in a Django routing file.
  """
  return RedirectView.as_view(url=targetUrl, permanent=True) 
开发者ID:Polychart,项目名称:builder,代码行数:7,代码来源:utils.py

示例10: temporaryRedirect

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def temporaryRedirect(targetUrl):
  """
  Simple shortcut for indicating a 302 redirect in a Django routing file.
  """
  return RedirectView.as_view(url=targetUrl, permanent=False) 
开发者ID:Polychart,项目名称:builder,代码行数:7,代码来源:utils.py

示例11: test_no_init_kwargs

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def test_no_init_kwargs(self):
        """
        A view can't be accidentally instantiated before deployment
        """
        with self.assertRaises(AttributeError):
            SimpleView(key='value').as_view() 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_base.py

示例12: test_no_init_args

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def test_no_init_args(self):
        """
        A view can't be accidentally instantiated before deployment
        """
        with self.assertRaises(TypeError):
            SimpleView.as_view('value') 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_base.py

示例13: test_pathological_http_method

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def test_pathological_http_method(self):
        """
        The edge case of a http request that spoofs an existing method name is caught.
        """
        self.assertEqual(SimpleView.as_view()(
            self.rf.get('/', REQUEST_METHOD='DISPATCH')
        ).status_code, 405) 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:test_base.py

示例14: test_get_only

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def test_get_only(self):
        """
        Test a view which only allows GET doesn't allow other methods.
        """
        self._assert_simple(SimpleView.as_view()(self.rf.get('/')))
        self.assertEqual(SimpleView.as_view()(self.rf.post('/')).status_code, 405)
        self.assertEqual(SimpleView.as_view()(
            self.rf.get('/', REQUEST_METHOD='FAKE')
        ).status_code, 405) 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:test_base.py

示例15: test_get_and_head

# 需要导入模块: from django.views.generic import TemplateView [as 别名]
# 或者: from django.views.generic.TemplateView import as_view [as 别名]
def test_get_and_head(self):
        """
        Test a view which supplies a GET method also responds correctly to HEAD.
        """
        self._assert_simple(SimpleView.as_view()(self.rf.get('/')))
        response = SimpleView.as_view()(self.rf.head('/'))
        self.assertEqual(response.status_code, 200) 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:test_base.py


注:本文中的django.views.generic.TemplateView.as_view方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。