我希望用户能够在付费后下载短片。我已经能够使支付网关工作。
这就是我想要做的事情:在用户付费并且付款成功后,他将被重定向回上一页,他将下载该文件。
我面临的挑战是在模板中输出下载链接,供用户付款后下载。我写了下面的代码,但没有成功,if语句没有带出下载链接:
Views.py
@csrf_exempt
def item_view(request,urlhash):
post = get_object_or_404(Arts,urlhash=urlhash)
stats= Arts.objects.filter(urlhash=urlhash).update(usage_count=F('usage_count')+1)
currentUrl=request.build_absolute_uri()
return render_to_response('postdetail.html',{'Arts':Arts,'post':post, 'stats':stats, 'currentUrl':currentUrl},context_instance=RequestContext(request))
@login_required
def document_view(request, arts_id):
document=Arts.objects.get(id=arts_id)
response = HttpResponse()
response["Content-Disposition"]= "attachment; filename={0}".format(document.pretty_name)
response['X-Accel-Redirect'] = "/protected_files/{0}".format(document.upfile.name)
return response
模板
<form method='POST' action='https://mackpay.com/pay/'>
{% csrf_token %}
<input type='hidden' name='v_merchant_id' value='{{newpayy.v_merchant_id}}' />
<input type='hidden' name='item_1' value='{{ newpayy.art.title }}' />
<input type='hidden' name='description_1' value='{{ newpayy.art.description }}' />
<input type='hidden' name='price_1' value='{{ newpayy.art.price }}' />
<input type='hidden' name='notify_url' value='127.0.0.1:8000/final_result'/>
#page to redirect to after payment
<input type='hidden' name='success_url' value='http://127.0.0.1:8000/i/{{ newpayy.art.urlhash }}/' />
<input type='image' src='http://mackpay.com/images/buttons/buynow_blue.png' alt='Make Payment' />
</form>
{% if request.META.HTTP_REFERER == 'https://mackpay.com/pay/' %}
<p> Download: <a href="{% url document_view post.id %}"> Get Stuff</a> </p>
{% endif %}
有关如何解决这个问题的想法吗?