本文整理汇总了Python中django.views.generic.View类的典型用法代码示例。如果您正苦于以下问题:Python View类的具体用法?Python View怎么用?Python View使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了View类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, **kwargs):
"""
Sets up a context object for views to augment. Populates it with the top level
articles from the DB.
@todo look into RequestContext for a better method of doing this
@todo look into memcache so the db isn't hit on every request
"""
View.__init__(self, **kwargs)
示例2: __init__
def __init__(self, **kwargs):
View.__init__(self, **kwargs)
self.language = ''
self.request = None
self.params = {}
self.responsesxml = etree.Element('REPONSES')
self.responsexml = etree.SubElement(self.responsesxml, 'REPONSE')
self.items = None
self.item = None
self.is_new = False
self.has_changed = False
示例3: __init__
def __init__(self, **kwargs):
View.__init__(self, **kwargs)
self.language = ''
self.request = None
self.params = {}
self.responsejson = {}
self.items = None
self.item = None
self.is_new = False
self.has_changed = False
self.format = 'JSON'
示例4: __init__
def __init__(self, **kwargs):
View.__init__(self, **kwargs)
# Allow this view to easily switch between feed formats.
format = kwargs.get('format', self.format)
try:
self.feed_type = _FEED_FORMATS[format]
except KeyError:
raise ValueError("Unsupported feed format: {0}. Supported are: {1}".format(
self.format, ', '.join(sorted(_FEED_FORMATS.iterkeys()))
))
示例5: dispatch
def dispatch(self, request, *args, **kwargs):
# Authentication
if not users.get_current_user().email() in settings.AUTHORIZED_USER:
if not 'localhost' == request.META['SERVER_NAME']:
if not 0 == len(settings.AUTHORIZED_USER):
return HttpResponse(status=403)
return View.dispatch(self, request, *args, **kwargs)
示例6: dispatch
def dispatch(self, request, *args, **kwargs):
if not self.has_permission(request, *args, **kwargs):
if not request.user.is_authenticated():
path = request.get_full_path()
return HttpResponseRedirect("%s?next=%s" % (settings.LOGIN_URL,
path))
else:
return render_to_forbidden(request)
return _View.dispatch(self, request, *args, **kwargs)
示例7: test_post_process_urls_adds_decorator
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')
示例8: setUp
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}
示例9: assert_status
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
示例10: path
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
示例11: patterns
"""
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')
)
示例12: __init__
def __init__(self, **kwargs):
View.__init__(self, **kwargs)
self.form = None
self.form_values = None
self.term = None
示例13: patterns
from django.conf.urls import patterns, url
from django.views.generic import View
urlpatterns = patterns(
'',
url(r'^simple/action/$', View.as_view(), name='simpleAction'),
)
示例14: get_extra_urls
def get_extra_urls(self):
return patterns('',
url(r'^login/$',
View.as_view(),
name='login'),
)
示例15: dispatch
def dispatch(self, request, *args, **kwargs):
return View.dispatch(self, request, *args, **kwargs)