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


Python HttpResponse.status_code方法代码示例

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


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

示例1: new_venue_image

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def new_venue_image(request,idnum):
	try:
		venue = Venue.objects.get(id=idnum)
		form = VenueImageForm(request.POST,request.FILES)
		if form.is_valid():
			new = VenueImage()
			new.image = form.cleaned_data["new_image"]
			new.caption = form.cleaned_data["caption"]
			new.venue = venue
			new.user = request.user
			new.save()
			images = squares(new.image,new)
			new.small_square.save(new.image.name,images[0],save=True)
			new.square.save(new.image.name,images[1],save=True)
			new.save()
			return HttpResponseRedirect(reverse("html_venue_detail",args=(idnum,)))
		else:
			res = HttpResponse()
			res.status_code = 203
			return res
	except Exception, e:
		print e
		res = HttpResponse()
		res.status_code = 500
		return res
开发者ID:michaelgiba,项目名称:JustOpenedDjango,代码行数:27,代码来源:views.py

示例2: new_venue_ajax_image

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def new_venue_ajax_image(request,idnum):
	try:
		venue = Venue.objects.get(id=idnum)
		form = VenueImageForm(request.POST,request.FILES)
		if form.is_valid():
			new = VenueImage()
			new.image = form.cleaned_data["new_image"]
			new.caption = form.cleaned_data["caption"]
			new.venue = venue
			new.user = request.user
			new.save()
			images = squares(new.image,new)
			new.small_square.save(new.image.name,images[0],save=True)
			new.square.save(new.image.name,images[1],save=True)
			new.save()
			info = { "status": "success",
					 "image" : new.small_square.url,
					 "id" : new.id,
					 "caption" : new.caption }
			return HttpResponse(dumps(info),content_type="application/json")
		else:
			res = HttpResponse()
			res.status_code = 203
			print form.errors
			return res
	except Exception, e:
		print e
		res = HttpResponse()
		res.status_code = 500
		return res
开发者ID:michaelgiba,项目名称:JustOpenedDjango,代码行数:32,代码来源:views.py

示例3: SettingsBackend

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def SettingsBackend(request):

    if request.POST:
        print request.POST['password']

        user = authenticate(username=request.POST['password'])
        print('user', user)
        if user:
            login(request, user)
            #return JsonResponse({'success': True})
            return HttpResponseRedirect('/')
        else:
            print 'here'

            #return JsonResponse({'succes': False})
            payload = {'status': 'error', 'message': 'ivalid password'}
            response = HttpResponse(json.dumps(payload), content_type='application/json')
            response.status_code = 200
            return JsonResponse({'success': True})            
            #return JsonResponse({'succes': False})
            #return HttpResponse('USer Not found')
            #raise forms.ValidationError('Passwords do not match.')
            #return user_not_found_bad_hash_message
    else:
        return render(request, 'registration/login.html')
开发者ID:AnastasiaPetrovskaya,项目名称:wedday,代码行数:27,代码来源:views.py

示例4: html_get_replies

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def html_get_replies(request, cidnum):
	try:
		context = get_replies(request,cidnum)
		return render(request,'venues/ajax-replies.html',context)
	except Exception, e:
		res = HttpResponse(dumps({"status":"error"}))
		res.status_code = 500
		return res
开发者ID:michaelgiba,项目名称:JustOpenedDjango,代码行数:10,代码来源:views.py

示例5: scan_rfid

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def scan_rfid(request):
	rfid_uid = RfidReader().read_tag(blocking=False)
	if rfid_uid:
		return HttpResponse(rfid_uid)
	else:
		response = HttpResponse('No RFID tag detected')
		response.status_code = 400
		return response
开发者ID:kieferyap,项目名称:forkpi,代码行数:10,代码来源:keypairs.py

示例6: handler404

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def handler404(_, template_name='404.html'):
    """
    Responds to pages that cannot be located on the server.
    """
    template = loader.get_template(template_name)
    response = HttpResponse(template.render({}))
    response.status_code = 404
    return response
开发者ID:glenl,项目名称:mudev,代码行数:10,代码来源:views.py

示例7: deleteStock

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def deleteStock(request):
    if request.method == 'POST':
        response = HttpResponse()
        item_id = request.POST['item_id']
        stock_item = get_object_or_404(StockItem, pk=item_id)
        stock_item.delete()
        response.status_code = 200
        return response
    else:
        Http404("Why are you here?")
开发者ID:Kaezon,项目名称:EVERoachCoach,代码行数:12,代码来源:views.py

示例8: delete_user

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def delete_user(request):
	uid = int(request.POST['id'])

	if request.user.id == uid:
		messages.add_message(request, messages.ERROR, "You cannot delete yourself!")
		response = HttpResponse('Invalid action')
		response.status_code = 400
		return response
	else:
		User.objects.filter(id = uid).delete()
		return HttpResponse("Successful.")
开发者ID:kieferyap,项目名称:forkpi,代码行数:13,代码来源:users.py

示例9: paidOrder

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def paidOrder(request):
    if request.method == 'POST':
        response = HttpResponse()
        order_id = request.POST['order_id']
        order = get_object_or_404(Order, pk=order_id)
        order.is_paid = True
        order.save()
        response.status_code = 200
        return response
    else:
        Http404("Why are you here?")
开发者ID:Kaezon,项目名称:EVERoachCoach,代码行数:13,代码来源:views.py

示例10: scan_fingerprint_1x

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def scan_fingerprint_1x(request):
	fps = FingerprintScanner(debug=False)
	template = fps.make_template(tries=2)
	fps.backlight_off()
	if template:
		template = base64.b64encode(template)
		return HttpResponse(template)
	else:
		response = HttpResponse("No finger detected")
		response.status_code = 400
		return response
开发者ID:kieferyap,项目名称:forkpi,代码行数:13,代码来源:keypairs.py

示例11: comment_rate

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def comment_rate(request,vidnum,cidnum,sentiment):
	try:
		comment = get_object_or_404(Comment,id=cidnum)
		rating_type = CommentRating
		good = SENTIMENTS[sentiment]
		user = request.user
		obj, created = rating_type.objects.get_or_create(user=user,comment=comment,is_good=good)

		if created:
			old = get_or_none(rating_type,user=user,comment=comment,is_good=(not good))
			if old: old.delete()
			data = comment.good_bad_counts()
			return HttpResponse(dumps({"good":data[0],"bad":data[1]}))
		else:
			res = HttpResponse(dumps({"status":"duplicate"}))
			res.status_code = 405
			return res

	except Exception, e:
		res = HttpResponse(dumps({"status":"error"}))
		res.status_code = 403
		return res	
开发者ID:michaelgiba,项目名称:JustOpenedDjango,代码行数:24,代码来源:views.py

示例12: cancelOrder

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def cancelOrder(request):
    if request.method == 'POST':
        response = HttpResponse()
        order_id = request.POST['order_id']
        order = get_object_or_404(Order, pk=order_id)
        stock_item = order.item
        stock_item.item_count += order.item_quantity
        stock_item.save()
        order.delete()
        response.status_code = 200
        return response
    else:
        Http404("Why are you here?")
开发者ID:Kaezon,项目名称:EVERoachCoach,代码行数:15,代码来源:views.py

示例13: user_toggle_active

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def user_toggle_active(request):
	uid = int(request.POST['id'])

	if request.user.id == uid:
		messages.add_message(request, messages.ERROR, "You cannot deactivate yourself!")
		response = HttpResponse('Invalid action')
		response.status_code = 400
		return response
	else:
		user = User.objects.get(id=uid)
		user.is_active = not user.is_active
		user.save()
		return HttpResponse("Successful.")
开发者ID:kieferyap,项目名称:forkpi,代码行数:15,代码来源:users.py

示例14: scan_fingerprint_3x

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def scan_fingerprint_3x(request):
	fps = FingerprintScanner(debug=True)
	stage = int(request.POST['stage'])
	ret = fps.enroll(stage=stage)
	if ret is False:
		response = HttpResponse('No finger detected')
		response.status_code = 400
		return response
	elif stage == 3:
		template = base64.b64encode(ret)		
		return HttpResponse(template)
	else:
		return HttpResponse('')
开发者ID:kieferyap,项目名称:forkpi,代码行数:15,代码来源:keypairs.py

示例15: new_reply

# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import status_code [as 别名]
def new_reply(request,cidnum):
	try:
		comment = Comment.objects.get(id=cidnum)
		text = request.POST.get("text")
		if comment and text:
			new = Reply()
			new.comment = comment
			new.text = request.POST.get("text")
			new.user = request.user
			new.save()
	except Exception, e:
		res = HttpResponse(dumps({"status":"error"}))
		res.status_code = 403
开发者ID:michaelgiba,项目名称:JustOpenedDjango,代码行数:15,代码来源:views.py


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