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


Python View.as_view方法代码示例

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


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

示例1: test_post_process_urls_adds_decorator

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
    def test_post_process_urls_adds_decorator(self):
        fake_decorator = mock.Mock()
        fake_decorator.return_value = 'fake_callback'

        application.get_url_decorator = mock.Mock()
        application.get_url_decorator.return_value = fake_decorator

        pattern = url('^$', View.as_view(), name='index')
        processed_patterns = application.post_process_urls([pattern])

        application.get_url_decorator.assert_called_once_with(pattern)
        self.assertEqual(processed_patterns[0].callback, 'fake_callback')
开发者ID:marangonico,项目名称:django-oscar,代码行数:14,代码来源:test_application.py

示例2: setUp

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
    def setUp(self):
        self.user = UserFactory()

        self.authed_view = TemplateView.as_view(template_name='base.html')
        self.authed_view_kwargs = {'authed': True}
        self.anonymous_view = TemplateView.as_view(template_name='base.html')
        self.anonymous_view_kwargs = {'anonymous': True}
        self.other_anonymous_view = View.as_view()
        self.view_kwargs = {
            'authed_view': self.authed_view,
            'authed_view_kwargs': self.authed_view_kwargs,
            'anonymous_view': self.anonymous_view,
            'anonymous_view_kwargs': self.anonymous_view_kwargs}
开发者ID:epicbagel,项目名称:django-libs,代码行数:15,代码来源:views_tests.py

示例3: assert_status

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
def assert_status(
    code: int,
    user: settings.AUTH_USER_MODEL,
    view: View,
    challenge: Challenge,
    rf: RequestFactory,
):
    request = rf.get("/rand")
    request.challenge = challenge

    if user is not None:
        request.user = user

    view = view.as_view()

    if code == 403:
        with pytest.raises(PermissionDenied):
            view(request)
        response = None
    else:
        response = view(request)
        assert response.status_code == code

    return request, response
开发者ID:comic,项目名称:comic-django,代码行数:26,代码来源:utils.py

示例4: patterns

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
from django.conf.urls import patterns, url
from django.views.generic import View

urlpatterns = patterns(
    '',
    url('', View.as_view()),
)
开发者ID:Ixxy-Open-Source,项目名称:django-after-response,代码行数:9,代码来源:test_urls.py

示例5: test_get_url_decorator_fetches_correct_perms

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
 def test_get_url_decorator_fetches_correct_perms(self, mock_permissions_required):
     pattern = url('^$', View.as_view(), name='index')
     application.get_url_decorator(pattern)
     mock_permissions_required.assert_called_once_with('is_staff', login_url=None)
开发者ID:marangonico,项目名称:django-oscar,代码行数:6,代码来源:test_application.py

示例6: path

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
        views.InstrumentDetail.as_view(),
        name="instrument_detail",
    ),
    path(
        "stations/<int:station_id>/timeseries/<int:pk>/",
        views.TimeseriesDetail.as_view(),
        name="timeseries_detail",
    ),
    path("admin/", admin.site.urls),
    path("api/", include(enhydris_api_urls)),
    # For the following, see ticket #181
    path("timeseries/data/", views_old.timeseries_data, name="timeseries_data"),
]

# A view that does nothing, that will be used in some fake patterns below
_null_view = View.as_view()

# When a user registers, an email is sent, containing a link that the user has to click
# in order to confirm the email. In order to create that link, django-rest-auth uses
# reverse("account_confirm_email"). So we include that in the urlpatterns, although it's
# not actually being used and should not be served by Django. The web server should be
# configured to route that URL to the front-end, which should then POST to the
# verify-email API endpoint in order to perform the actual verification.
urlpatterns += [
    path("confirm-email/<str:key>/", _null_view, name="account_confirm_email")
]

# When a user registers, django-allauth runs reverse("account_email_verification_sent")
# in order to redirect to a page that says "We sent an email verification, click the
# link in that email". In our case, registration is done by POST to an API endpoint,
# which merely responds with "201". However, because something in django-allauth or in
开发者ID:openmeteo,项目名称:enhydris,代码行数:33,代码来源:urls.py

示例7: patterns

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
"""
URLs for filebrowser in TinyMCE
"""
from django.conf.urls import url
from django.conf.urls import patterns
from django.views.generic import View

from zinnia_tinymce.views import RemoveFileView
from zinnia_tinymce.views import FileBrowserView
from zinnia_tinymce.views import FileBrowserCallBackView


urlpatterns = patterns(
    '',
    url(r'^$',
        View.as_view(),
        name='tinymce-filebrowser-dispatch'),
    url(r'^callback.js$',
        FileBrowserCallBackView.as_view(),
        name='tinymce-filebrowser-callback'),
    url(r'^(?P<file_type>\w+)/$',
        FileBrowserView.as_view(),
        name='tinymce-filebrowser'),
    url(r'^(?P<file_type>\w+)/remove/(?P<pk>\d+)/$',
        RemoveFileView.as_view(),
        name='tinymce-filebrowser-remove')
)
开发者ID:DOE-NEPA,项目名称:zinnia-wysiwyg-tinymce,代码行数:29,代码来源:filebrowser.py

示例8: get_extra_urls

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
 def get_extra_urls(self):
     return patterns('',
         url(r'^login/$',
             View.as_view(),
             name='login'),
     )
开发者ID:pculture,项目名称:django-djam,代码行数:8,代码来源:test_base.py

示例9: patterns

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
# -*- coding: utf-8 -*-

from django.conf.urls import patterns, include, url
from django.views.generic import View


urlpatterns = patterns('',
    url(r'foo$', View.as_view(), name="foo"),
)
开发者ID:Automatique,项目名称:django-sites,代码行数:11,代码来源:urls.py

示例10: patterns

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
from django.conf.urls import patterns, include, url
from django.views.generic import View
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    url("foo/$", View.as_view(), name="foo"),
    url(r'^', include('staff.urls')),
    url(r'^admin/', include(admin.site.urls)),
)
开发者ID:pombredanne,项目名称:django-listable,代码行数:13,代码来源:urls.py

示例11: url

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
from django.conf.urls import url
from django.views.generic import View

urlpatterns = [
    url(r"^(?P<year>\d{4})/(?P<month>\d{1,2})/$", View.as_view(), name="monthly"),
    url(r"^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$", View.as_view(), name="daily"),
]
开发者ID:pinax,项目名称:pinax-calendars,代码行数:9,代码来源:urls.py

示例12: url

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
from django.conf.urls import url
from django.views.generic import View

urlpatterns = [
    url(r'^test_changed_urlconf/$', View.as_view(), name='test_changed_urlconf'),
]
开发者ID:ierror,项目名称:django-js-reverse,代码行数:8,代码来源:test_urlconf_urls.py

示例13: HttpResponse

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
"""URLs for the test app."""
from django.conf.urls.defaults import patterns, url
from django.http import HttpResponse
from django.views.generic import View

from django_libs import views

View.get = lambda req, *args, **kwargs: HttpResponse('SUCCESS!')
authed_view = View.as_view()
authed_view_kwargs = {'authed': True}
anonymous_view = View.as_view()
anonymous_view_kwargs = {'anonymous': True}


urlpatterns = patterns(
    '',
    url(r'^$', views.HybridView.as_view(
        authed_view=authed_view,
        authed_view_kwargs=authed_view_kwargs,
        anonymous_view=anonymous_view,
        anonymous_view_kwargs=anonymous_view_kwargs,
        ), name='dummy_hybrid'),
    url(r'^update-session/$', views.UpdateSessionAJAXView,
        name='update_session'),
    url(r'^prototype/(?P<template_path>.*)$',
        views.RapidPrototypingView.as_view(),
        name='prototype')
)
开发者ID:pombredanne,项目名称:django-libs,代码行数:30,代码来源:urls.py

示例14: patterns

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
from django.conf.urls import patterns, url
from django.views.generic import View


urlpatterns = patterns(
    '',
    url(r'^simple/action/$', View.as_view(), name='simpleAction'),
)
开发者ID:Anirudh58,项目名称:django-mini-project,代码行数:10,代码来源:urls.py

示例15: patterns

# 需要导入模块: from django.views.generic import View [as 别名]
# 或者: from django.views.generic.View import as_view [as 别名]
from django.conf.urls import patterns, url
from django.views.generic import View

urlpatterns = patterns('', 
        url(r'^(?P<pk>[\w\d]+)/module/$', View.as_view(), name='module')
)
开发者ID:JasYoung314,项目名称:moduleplanner-django,代码行数:8,代码来源:urls.py


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