如果session_order_reference为空,我想重定向用户。但是,Django一直运行到i.ticket.event.currency
,直到出现错误local variable 'currency' referenced before assignment
。我以为一旦调用重定向,它就会停止在那儿,而只是重定向用户。我在那里错了吗?
def checkout_page(request):
session_order_reference = request.session.get('order_reference')
if not request.session.get('order_reference'):
redirect('website:index') # TODO Marc: Better change to direct event link
reserved_item = ReservedItem.objects.filter(order_reference=session_order_reference)
d = {}
total_amount = total_tax_amount = 0
order_item_data = []
for i in reserved_item:
currency = i.ticket.event.currency
答案 0 :(得分:0)
重定向是一种响应,您需要将其返回:
if not request.session.get('order_reference'):
return redirect('website:index')