當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。