Python django.views.generic.base 模块,TemplateView() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用django.views.generic.base.TemplateView()

项目:maas    作者:maas    | 项目源码 | 文件源码
def post(self, request, *args, **kwargs):
        """Called by `TemplateView`: handle a POST request."""
        self.object = user = self.get_object()
        next_page = reverse('settings')

        # Process the profile-editing form, if that's what was submitted.
        profile_form, response = process_form(
            request, EditUserForm, next_page, 'profile', "Profile updated.",
            {'instance': user})
        if response is not None:
            return response

        # Process the password change form, if that's what was submitted.
        password_form, response = process_form(
            request, AdminPasswordChangeForm, next_page, 'password',
            "Password updated.", {'user': user})
        if response is not None:
            return response

        return self.respond(request, profile_form, password_form)
项目:montage    作者:storyful    | 项目源码 | 文件源码
def make_overview(module, urls, namespace):
    """Given the URLs for a bunch of views and the module they came from this
    generates an overview page with a title, description and a list of links
    to execute the views.
    """
    title = get_module_name(module).title()
    description = module.__doc__

    class OverView(TemplateView):
        template_name = 'auto_task_overview.html'

        def get_context_data(self, **kwargs):
            ctx = super(OverView, self).get_context_data(**kwargs)
            ctx.update({'title': title, 'description': description})

            view_links = []
            for url in urls:
                view = url.callback
                view_links.append({
                    'url_name': '%s:%s' % (
                        namespace, url.name
                    ) if namespace else url.name,
                    'view_name': funcname(view, rep=' '),
                    'view_description': view.__doc__ or '',
                })

            ctx['view_links'] = sorted(
                view_links, key=lambda d: d['view_name'])
            return ctx

    return OverView.as_view()
项目:maas    作者:maas    | 项目源码 | 文件源码
def get(self, request, *args, **kwargs):
        """Called by `TemplateView`: handle a GET request."""
        self.object = user = self.get_object()
        profile_form = EditUserForm(instance=user, prefix='profile')
        password_form = AdminPasswordChangeForm(user=user, prefix='password')
        return self.respond(request, profile_form, password_form)