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


Python HttpResponse.set_cookie方法代码示例

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


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

示例1: run

# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import set_cookie [as 别名]
    def run(self):
        
        if self.input_Request.GET.get("unlogin")!=None:
            return self.unlogin()

        beijing={"id":1,"name":"北京"}
        shanghai={"id":2,"name":"上海"}
        userAreas=[beijing,shanghai]
        dataset={"result":"","areas":userAreas}
        
        if self.input_Request.method=="POST":
            getUserName=self.input_Request.POST.get("txtUserName")
            getUserPass=self.input_Request.POST.get("txtUserPass")
            
            Login_result=self.login(getUserName,getUserPass)
        
            if Login_result:
                myResponse=HttpResponse("<script>self.location='/index/index'</script>")
                myResponse.set_cookie("userlogin_username",getUserName,3600)
                return myResponse
            else:
                dataset["result"]="用户名和密码错误"
            
        myResponse=render_to_response("userlogin.html",dataset)  

        return render_to_response("userlogin.html",dataset)    
开发者ID:Tinyhome,项目名称:pyweb,代码行数:28,代码来源:userloginController.py

示例2: set_color

# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import set_cookie [as 别名]
def set_color(request):
    if "favorite_color" in request.GET:

        # Create an HttpResponse object...
        response = HttpResponse("Your favorite color is now %s" %
                                request.GET["favorite_color"])

        # ... and set a cookie on the response
        response.set_cookie("favorite_color",
                            request.GET["favorite_color"])

        return response

    else:
        return HttpResponse("You didn't give a favorite color.")
开发者ID:gino2010,项目名称:djangobook2.0,代码行数:17,代码来源:views.py

示例3: get

# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import set_cookie [as 别名]
    def get(self, request):
        invalid_response = self.is_valid(request)

        if invalid_response:
            return invalid_response

        if not self.client.path_valid(
            request.GET.get('pth', '')
        ) or not self.client.ip_valid(self.client_ip):
            return HttpResponse(status=204) # NO_CONTENT

        tracking_id = request.GET.get(
            'dti', request.session.get('dja_tracking_id')
        )
        user_id = request.GET.get(
            'du', request.COOKIES.get('dja_uuid')
        )
        data = {
            'domain': self.parsed_url.netloc,
            'protocol': self.parsed_url.scheme,
            'client': self.client,
            'ip_address': self.client_ip,
            'user_agent': request.META.get('HTTP_USER_AGENT', 'None'),
            'path': request.GET.get('pth', ''),
            'query_string': request.GET.get('qs', ''),
            'referrer': request.GET.get('rf', '')[:2083],
            'screen_width': request.GET.get('sw'),
            'screen_height': request.GET.get('sh'),
        }
        status = 201 # CREATED
        if tracking_id:
            data['tracking_key'] = tracking_id
            status = 202 # ACCEPTED
        if user_id:
            data['tracking_user_id'] = user_id
            status = 202 # ACCEPTED
        new_event = models.RequestEvent.objects.create(**data)
        if not tracking_id:
            request.session['dja_tracking_id'] = new_event.tracking_key
        img_data = file(os.path.join(TRACKING_PIXEL_PATH, 'tracking_pixel.png')).read()
        response = HttpResponse(content=img_data, status=status, content_type='image/png')
        response.set_cookie('dja_uuid', new_event.tracking_user_id,
                            expires=datetime.now() + timedelta(days=365))
        return response
开发者ID:analytehealth,项目名称:django-analytics,代码行数:46,代码来源:views.py

示例4: plan_list

# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import set_cookie [as 别名]
def plan_list(request):
    '''
           巡检计划的展示页面
    '''  
    logger.info(u'查看巡检计划')
    q_system = ''
    try:
       q_system=request.REQUEST['system']
    except:
        q_system = request.COOKIES["system"]
    cur_system_instance = System.objects.get(name=q_system)
    tasks = Task.objects.filter(system=cur_system_instance)
    plans = Plan.objects.filter(task__in=tasks)
    context = {'plans': plans}
    t = get_template('plans.html')
    html = t.render(context)
    response = HttpResponse(html)
    response.set_cookie("system",q_system)
    return response
开发者ID:sgcccoder,项目名称:InspectionCloudMaster,代码行数:21,代码来源:views.py

示例5: home_page

# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import set_cookie [as 别名]
def home_page(request):
#     print request.session.keys['']
    print request.user.is_authenticated()
    res = HttpResponse("<html><body>this is books home page..</body></html>")
    if request.session.test_cookie_worked():
        session_id = request.COOKIES['sessionid']
        print session_id
        session = Session.objects.get(session_key=session_id)
        print session.session_data
        print session.get_decoded()
#         request.session.delete_test_cookie()
        res = HttpResponse('cookie is worked.')
        return res
    else:
        request.session.set_test_cookie()
        res = HttpResponse('open cookie.')
        res.set_cookie('mykey', 'myvalue')
        return res
    return res
开发者ID:soszrg,项目名称:web,代码行数:21,代码来源:views.py

示例6: post

# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import set_cookie [as 别名]
    def post(self, *args, **kwargs):
        response = HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
        message = get_object_or_404(models.Message, pk=int(self.request.POST.get('id')))
        if self.request.user.is_authenticated():
            try:
                rel = models.MessageToUser.objects.get(user=self.request.user, message=message)
            except models.MessageToUser.DoesNotExist:
                rel = models.MessageToUser(user=self.request.user, message=message)

            rel.viewed = True
            rel.save()
        else:
            viewed = [unicode(message.pk)]
            in_cookies = self.request.COOKIES.get('djxami', None)
            if in_cookies and len(in_cookies) < 1000:
                viewed += in_cookies.split(':')
            print viewed
            response.set_cookie('djxami',
                                str(':'.join(set(viewed))),
                                expires=now() + timedelta(days=365),
                                domain=settings.SESSION_COOKIE_DOMAIN,
                                secure=settings.SESSION_COOKIE_SECURE or None)

        return response
开发者ID:xacce,项目名称:djxami,代码行数:26,代码来源:views.py

示例7: auth_csrf

# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import set_cookie [as 别名]
def auth_csrf(request):
    ctkn = unicode(csrf(request)['csrf_token'])
    response = HttpResponse(status=204)
    response.set_cookie("csrftoken", ctkn)
    return response
开发者ID:zosiakropka,项目名称:academia,代码行数:7,代码来源:auth.py


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