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


Python RedirectView.as_view方法代码示例

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


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

示例1: get_urls

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView import as_view [as 别名]
def get_urls(self):
        from django.urls import path

        def wrap(view):
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            wrapper.model_admin = self
            return update_wrapper(wrapper, view)

        info = self.model._meta.app_label, self.model._meta.model_name

        urlpatterns = [
            path('', wrap(self.changelist_view), name='%s_%s_changelist' % info),
            path('add/', wrap(self.add_view), name='%s_%s_add' % info),
            path('autocomplete/', wrap(self.autocomplete_view), name='%s_%s_autocomplete' % info),
            path('<path:object_id>/history/', wrap(self.history_view), name='%s_%s_history' % info),
            path('<path:object_id>/delete/', wrap(self.delete_view), name='%s_%s_delete' % info),
            path('<path:object_id>/change/', wrap(self.change_view), name='%s_%s_change' % info),
            # For backwards compatibility (was the change url before 1.9)
            path('<path:object_id>/', wrap(RedirectView.as_view(
                pattern_name='%s:%s_%s_change' % ((self.admin_site.name,) + info)
            ))),
        ]
        return urlpatterns 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:26,代码来源:options.py

示例2: get_urls

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView import as_view [as 别名]
def get_urls(self):
        from django.conf.urls import url

        def wrap(view):
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            wrapper.model_admin = self
            return update_wrapper(wrapper, view)

        info = self.model._meta.app_label, self.model._meta.model_name

        urlpatterns = [
            url(r'^$', wrap(self.changelist_view), name='%s_%s_changelist' % info),
            url(r'^add/$', wrap(self.add_view), name='%s_%s_add' % info),
            url(r'^(.+)/history/$', wrap(self.history_view), name='%s_%s_history' % info),
            url(r'^(.+)/delete/$', wrap(self.delete_view), name='%s_%s_delete' % info),
            url(r'^(.+)/change/$', wrap(self.change_view), name='%s_%s_change' % info),
            # For backwards compatibility (was the change url before 1.9)
            url(r'^(.+)/$', wrap(RedirectView.as_view(
                pattern_name='%s:%s_%s_change' % ((self.admin_site.name,) + info)
            ))),
        ]
        return urlpatterns 
开发者ID:Yeah-Kun,项目名称:python,代码行数:25,代码来源:options.py

示例3: test_invalid_keyword_argument

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView 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

示例4: autocomplete_view

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView import as_view [as 别名]
def autocomplete_view(self, request):
        return AutocompleteJsonView.as_view(model_admin=self)(request) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:4,代码来源:options.py

示例5: paged_list_view

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView import as_view [as 别名]
def paged_list_view(view, name):
    return include([
        url(r'^$', view.as_view(), name=name),
        url(r'^(?P<page>\d+)$', view.as_view(), name=name),
    ]) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:7,代码来源:urls.py

示例6: get_urls

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView import as_view [as 别名]
def get_urls(self):
        urls = [
            url(r'^$', RedirectView.as_view(url=settings.OSCAR_HOMEPAGE), name='home'),
        ] + super().get_urls()
        # excluding urls of catalogue and search
        exclude_app_urls(urls, 'catalogue')
        exclude_app_urls(urls, 'search')
        return urls 
开发者ID:edx,项目名称:ecommerce,代码行数:10,代码来源:config.py

示例7: template

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView 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

示例8: permanentRedirect

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView 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

示例9: temporaryRedirect

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView 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

示例10: test_no_init_kwargs

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView 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

示例11: test_no_init_args

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView 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

示例12: test_pathological_http_method

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView 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

示例13: test_get_only

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView 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

示例14: test_get_and_head

# 需要导入模块: from django.views.generic import RedirectView [as 别名]
# 或者: from django.views.generic.RedirectView 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

示例15: test_get_and_post

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


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