我一直在使用django框架背面的Python构建的商店,一切正常,直到我注意到当用户进行结帐并被请求登录时在他们这样做和他们的篮子倒空...明显这对篮子来说并不是一件好事,我想知道是什么造成了这种情况,是否可以查看一下我的代码并给出一些建议?我不知道该怎么做。用户登录时丢失会话数据
=====编辑 - 下面是我的代码,我将不胜感激,如果有人可以给我的,我怎么能阻止篮下清算一击,当用户登录=====
def basket(request):
"""
Display the current state of the basket and allow the customer to modify
the discount and quantities of each row of the basket
"""
data = {}
basket = Basket(request)
discount_form = DiscountCodeForm(basket)
if request.method == "POST":
if 'update' in request.POST:
basket.post_update(request)
discount_form = DiscountCodeForm(basket, request.POST)
if discount_form.is_valid():
cleaned_data = discount_form.cleaned_data
if cleaned_data['discount_code']:
basket.set_discount(Offer.objects.get(code=cleaned_data['discount_code']))
if 'delete' in request.POST:
basket.post_delete(request)
if 'remove_discount' in request.POST:
basket.remove_discount()
data['discount_form'] = discount_form
data['logged_in'] = persistent_account(request)
data['pageclass'] = 'basket'
data['category'] = Category.objects.root_category()
data['products'] = Product.objects.all()
data['regions'] = Zone.objects.all()
data['currency'] = Currency.get_default_currency()
return render_to_response('basket.html', data, RequestContext(request))
def login(request):
"""
Log the user in.
The form is where the actual login occurs. If already logged in, then
forward to the last attempted page, or, if came directly to the login page,
the account page.
@todo: Incorrect guesses limit of 10 then deactive account
"""
data = {}
redirect_to = request.GET.get('next', reverse('account'))
account = persistent_account(request)
if account:
return HttpResponseRedirect(reverse('account'))
if request.method == "POST":
login_form = LoginForm(request, request.POST)
# This next line will also cause a login
if login_form.is_valid():
login_form.user.message_set.create(message="You have successfully logged in. Welcome back.")
return HttpResponseRedirect(redirect_to)
else:
login_form = LoginForm(request)
data['shop_login_form'] = login_form
data['pageclass'] = 'customer_login'
return render_to_response('login.html', data, RequestContext(request))
我给你的是我的登录视图和篮子视图,如果不是随意喊我,那么这个视图就足够了。
您没有发布任何代码... – 2009-11-24 19:20:08
您是否正在使用自定义构建的购物车?的Satchmo?还有别的吗?你是否缩小了问题的根源?你在问什么? “来看看我的代码!”是咨询顾问的要求,咨询费用。 “为什么这段代码做错了什么?”是一个公平的问题,通常可以在这样的问题板上处理。 – jcdyer 2009-11-24 20:15:39
与jcd一致......我们需要更多详细信息,例如它正在做什么,正在打印的任何错误以及您可以提供的任何调试信息。如果它自己的代码尝试打印正在传递给检出的输出,并查看是否有任何事情是痛苦的并导致数据消失。 – 2009-11-24 20:17:54