本文整理汇总了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')
示例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}
示例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
示例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()),
)
示例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)
示例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
示例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')
)
示例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'),
)
示例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"),
)
示例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)),
)
示例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"),
]
示例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'),
]
示例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')
)
示例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'),
)
示例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')
)