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


Python TemplateResponse.render方法代码示例

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


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

示例1: verify_attendances

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
def verify_attendances(request):

    if 'attendance' in request.POST:
        for member in request.POST.getlist('attendance'):
            """attendance = Attendance.objects.get(pk=request.POST.get('attendance'))"""
            attendance = Attendance.objects.get(pk=member)
            attendance.verified = True
            attendance.save()

    if 'delete' in request.POST:
        for member in request.POST.getlist('delete'):
            attendance = Attendance.objects.get(pk=member)
            attendance.delete()

    order_by = request.GET.get('order_by', 'user')
    own_guild = request.user.userprofile.guild
    general_guild = Guild.objects.filter(id = general_id)

    if own_guild.abbreviation != 'TF':
        guild_users = User.objects.filter(userprofile__guild = own_guild)
    else:
        guild_users = User.objects.filter(userprofile__is_tf = True)

    unverified = Attendance.objects.filter(Q(user__in = guild_users) 
                                            & (Q(event__guild = own_guild) | Q(event__guild = general_guild))
                                            & Q(verified = False)).order_by(order_by)
    verified = Attendance.objects.filter(Q(user__in = guild_users) 
                                            & (Q(event__guild = own_guild) | Q(event__guild = general_guild))
                                            & Q(verified = True)).order_by(order_by)

    response = TemplateResponse(request, 'admin_attendances.html', {'unverified': unverified, 'verified': verified})
    response.render()
    return response
开发者ID:Jonneitapuro,项目名称:isoskaba2,代码行数:35,代码来源:views.py

示例2: test_pickling

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
    def test_pickling(self):
        # Create a template response. The context is
        # known to be unpickleable (e.g., a function).
        response = TemplateResponse(self.factory.get('/'),
            'first/test.html', {
                'value': 123,
                'fn': datetime.now,
            })
        self.assertRaises(ContentNotRenderedError,
                          pickle.dumps, response)

        # But if we render the response, we can pickle it.
        response.render()
        pickled_response = pickle.dumps(response)
        unpickled_response = pickle.loads(pickled_response)

        self.assertEquals(unpickled_response.content, response.content)
        self.assertEquals(unpickled_response['content-type'], response['content-type'])
        self.assertEquals(unpickled_response.status_code, response.status_code)

        # ...and the unpickled reponse doesn't have the
        # template-related attributes, so it can't be re-rendered
        self.assertFalse(hasattr(unpickled_response, '_request'))
        self.assertFalse(hasattr(unpickled_response, 'template_name'))
        self.assertFalse(hasattr(unpickled_response, 'context_data'))
        self.assertFalse(hasattr(unpickled_response, '_post_render_callbacks'))
开发者ID:MyaThandarKyaw,项目名称:django,代码行数:28,代码来源:response.py

示例3: index

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
def index(request):
	print " "
	print "*******VIEWS INDEX******"
	print " "
	response = TemplateResponse(request, 'index.html', {} )
	response.render()
	return response
开发者ID:marcelarosalesj,项目名称:Web,代码行数:9,代码来源:views.py

示例4: mount_owncloud

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
def mount_owncloud(request):
    # If the request is a http post
    if request.method == 'POST' and 'operation' not in request.POST:
        form = OwncloudForm(request.POST)

        if form.is_valid():
            # Mount ownCloud
            is_mounted = WebFolder.mount_owncloud(request.user, request.POST["user"], request.POST["password"])
            if is_mounted:
                message = "Your ownCloud directory was successfully mounted."
                t = TemplateResponse(request, 'info.html', 
                             {'message': message})
            else:
                message = "Mounting your ownCloud directory failed. Please try again!"
                t = TemplateResponse(request, 'error.html',
                             {'message': message})
            return HttpResponse(t.render())
        else:
            # The supplied form contained errors - just print them to the terminal.
            print form.errors
    else:
        # If the request was not a POST, display the form to enter details.
        form = OwncloudForm()
    
    t = TemplateResponse(request, 'collection/mount_owncloud.html', {'form': form})
    return HttpResponse(t.render())
开发者ID:lauflabor-tud,项目名称:chiara-v2,代码行数:28,代码来源:views.py

示例5: home

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
def home(request):
    html = "appointment.home"
    t = TemplateResponse(request, "base.html", {})
    t.template_name = "index.html"
    t.render()
    # return HttpResponse(html)
    return t
开发者ID:clinicli,项目名称:webapp,代码行数:9,代码来源:views.py

示例6: html_response

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
def html_response(request, response, content):
    """Return a html layout with sort options as the response content."""
    template = TemplateResponse(request, "profile_stats.html",
                                {"stats": content,
                                 "order_by": request.GET.get('profile', None)})
    template.render()
    return template
开发者ID:yitzc,项目名称:yet-another-django-profiler,代码行数:9,代码来源:middleware.py

示例7: test_pickling

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
    def test_pickling(self):
        # Create a template response. The context is
        # known to be unpicklable (e.g., a function).
        response = TemplateResponse(self.factory.get("/"), "first/test.html", {"value": 123, "fn": datetime.now})
        self.assertRaises(ContentNotRenderedError, pickle.dumps, response)

        # But if we render the response, we can pickle it.
        response.render()
        pickled_response = pickle.dumps(response)
        unpickled_response = pickle.loads(pickled_response)

        self.assertEqual(unpickled_response.content, response.content)
        self.assertEqual(unpickled_response["content-type"], response["content-type"])
        self.assertEqual(unpickled_response.status_code, response.status_code)

        # ...and the unpickled response doesn't have the
        # template-related attributes, so it can't be re-rendered
        template_attrs = ("template_name", "context_data", "_post_render_callbacks", "_request")
        for attr in template_attrs:
            self.assertFalse(hasattr(unpickled_response, attr))

        # ...and requesting any of those attributes raises an exception
        for attr in template_attrs:
            with self.assertRaises(AttributeError):
                getattr(unpickled_response, attr)
开发者ID:yogidtu,项目名称:django,代码行数:27,代码来源:test_response.py

示例8: test_pickling

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
    def test_pickling(self):
        # Create a template response. The context is
        # known to be unpicklable (e.g., a function).
        response = TemplateResponse(self.factory.get('/'),
            'first/test.html', {
                'value': 123,
                'fn': datetime.now,
            }
        )
        self.assertRaises(ContentNotRenderedError,
                          pickle.dumps, response)

        # But if we render the response, we can pickle it.
        response.render()
        pickled_response = pickle.dumps(response)
        unpickled_response = pickle.loads(pickled_response)

        self.assertEqual(unpickled_response.content, response.content)
        self.assertEqual(unpickled_response['content-type'], response['content-type'])
        self.assertEqual(unpickled_response.status_code, response.status_code)

        # ...and the unpickled response doesn't have the
        # template-related attributes, so it can't be re-rendered
        template_attrs = ('template_name', 'context_data',
            '_post_render_callbacks', '_request', '_current_app')
        for attr in template_attrs:
            self.assertFalse(hasattr(unpickled_response, attr))

        # ...and requesting any of those attributes raises an exception
        for attr in template_attrs:
            with self.assertRaises(AttributeError):
                getattr(unpickled_response, attr)
开发者ID:pexip,项目名称:os-python-django,代码行数:34,代码来源:test_response.py

示例9: process_response

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
 def process_response(self, request, response):
     if isinstance(response, HttpResponseNotAllowed):
         response = TemplateResponse(request=request,
                                     template="method_not_allowed.html",
                                     status=405,
                                     context={})
         response.render()
     return response
开发者ID:uclouvain,项目名称:osis,代码行数:10,代码来源:extra_http_responses_midleware.py

示例10: list_events

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
def list_events(request):
	"""
	Lists all events. Available only for admins.
	"""
	order_by = request.GET.get('order_by', 'name')
	events = Event.objects.all().order_by(order_by)
	response = TemplateResponse(request, 'admin_eventlist.html', {'events': events})
	response.render()
	return response
开发者ID:Jonneitapuro,项目名称:isoskaba2,代码行数:11,代码来源:views.py

示例11: render_tariff_plan_template

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
 def render_tariff_plan_template(upc_code):
     from django.template.response import TemplateResponse
     t_p = request.db_session.query(TariffPlan).\
         join(CompanyUpcTariffPlan).\
         filter_by(company=request.user.company).\
         filter_by(upc=upc_code).first()
     html = TemplateResponse(request, 'upc_detailed.html', {'upc': upc_code, 'movie': upc_code.movie, 'tariff_plan': t_p})
     html.render()
     return html
开发者ID:adam1978828,项目名称:webapp1,代码行数:11,代码来源:views.py

示例12: user_ranking

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
def user_ranking(request):

    usersGuild = User.objects.filter(Q(userprofile__guild = request.user.userprofile.guild) & Q(userprofile__role = 'user'))
    #usersAll = User.objects.filter(Q(userprofile__role = 'user'))
    score_list_guild = get_user_ranking(usersGuild)
    score_list_guild = sorted(score_list_guild, key=lambda points: points[3], reverse=True)
    #score_list_all = get_user_ranking(usersAll) This shit will likely crash the whole site
    #score_list_all = sorted(score_list_all, key=lambda points: points[3], reverse=True)[:20]
    response = TemplateResponse(request, 'userrank.html', {'score_list_guild': score_list_guild})
    response.render()
    return response
开发者ID:Jonneitapuro,项目名称:isoskaba2,代码行数:13,代码来源:views.py

示例13: IndexView

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
def IndexView(request):
    template_name = 'index.html'
    dict = {}
    
    posts = lp_posts.objects.all()
    options = lp_options.objects.all()
    dict['posts'] = posts
    
    t = TemplateResponse(request, 'index.html', dict)
    t.render()
    return t
开发者ID:zblhero,项目名称:litpress,代码行数:13,代码来源:views.py

示例14: user_info

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
def user_info(request):
    cur_user = request.user
    cur_user_profile = UserProfile.objects.get(user_id = cur_user.id)
    attendances = Attendance.objects.filter(user = cur_user)
    points = sum([x.event.points for x in attendances])
    response = TemplateResponse(request, 'user_info.html', {
        'profile': cur_user_profile,
        'attendances': attendances,
        'user_points': points
    })
    response.render()
    return response
开发者ID:Jonneitapuro,项目名称:isoskaba2,代码行数:14,代码来源:views.py

示例15: test_render_page

# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import render [as 别名]
    def test_render_page(self):
        template_string = 'url: {{ get_protected_url(page) }}'
        template = engines['wagtail-env'].from_string(template_string)

        page = self.make_page(path='foo', live=True)
        request = self.request_for_hostname('localhost')
        context = page.get_context(request)

        response = TemplateResponse(request, template, context)
        response.render()

        self.assertEqual(response.content, 'url: /foo/')
开发者ID:marcesher,项目名称:cfgov-refresh,代码行数:14,代码来源:test_links.py


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