python复制粘贴怎么错误_我把工作代码复制粘贴到IDE中,现在Python抛出了大量错误...

在将Django视图代码从一处复制粘贴到另一处后,作者遇到了大量的Python缩进和语法错误。尽管代码看起来正确,但无论使用TextWarangler还是Sublime Text,错误依然存在。尝试手动调整缩进并未解决问题,错误似乎会从一行转移到另一行。代码示例显示了一个涉及Stripe支付处理的视图函数。
摘要由CSDN通过智能技术生成

我复制并粘贴了代码到我的IDE(textwarangler)。现在,当我尝试运行我的代码时,我会得到大量关于缩进和无效语法的随机错误。在

在我将代码从一个Django视图复制粘贴到另一个视图之前,代码运行得非常好。我几乎百分之百地肯定代码在我的新视图中仍然是正确的,但是,每次运行它时,我都会遇到大量与缩进和无效语法相关的错误(甚至像“'”这样的多行注释也会触发“第234行的无效语法”错误)。在

我试过把IDE换成sublime,甚至把所有的凹痕都退格,然后再把它们重新划出来都没有用。每次我在一行上修复一个“错误”,另一行上就会创建一个新的错误。在

我的代码在下面,请让我知道如何修复。在@require_POST

def pay(request):

if request.method == 'POST':

form = CustomerForm(request.POST)

if form.is_valid():

# If the form has been submitted...

# All validation rules pass

#get the customer by session'd customer_id

c = get_object_or_404(Customer, pk = request.session['customer_id'])

#assign shipping info from POST to the customer object

c.first_name = request.POST['first_name']

c.last_name = request.POST['last_name']

c.street_address = request.POST['street_address']

c.city = request.POST['city']

c.state = request.POST['state']

c.zip = request.POST['zip']

#assign email info from POST to the customer object

c.email_address = request.POST['email_address']

stripe.api_key = REDACTED

# Get the credit card details submitted by the form

token = request.POST['stripeToken']

#tries to save the newly added form data.

try:

#save the new customer object's data

c.save()

########## THIS HANDLES CREATING A NEW STRIPE PAYMENT ################

# Create a Customer

try:

customer = stripe.Customer.create(

card=token,

plan="monthly",

email= c.email_address)

#need to save customer's id (ex: c.stripe_id = token.id)

#if there's a token error

except stripe.error.InvalidRequestError, e:

pass

#if the card is declined by Stripe

except stripe.error.CardError, e:

body = e.json_body

err = body['error']

print "Status is: %s" % e.http_status

print "Type is: %s" % err['type']

print "Code is: %s" % err['code']

# param is '' in this case

print "Param is: %s" % err['param']

print "Message is: %s" % err['message']

except stripe.error.AuthenticationError, e:

# Authentication with Stripe's API failed

# (maybe you changed API keys recently)

pass

except stripe.error.APIConnectionError, e:

# Network communication with Stripe failed

pass

except stripe.error.StripeError, e:

# Display a very generic error to the user, and maybe send

# yourself an email

pass

except Exception, e:

# Something else happened, completely unrelated to Stripe

pass

return render(request, 'shipment/confirm.html', {'date' : 'April 15, 2014'})

#passes the context to the template for confirming the customer's data

#context = { 'email_address' : c.email_address, 'first_name' : c.first_name,

# 'last_name' : c.last_name, 'street_address' : c.street_address,

# 'city' : c.city, 'state' : c.state, 'zip' : c.zip, }

#return render(request, 'shipment/pay.html', context)

#If there is a duplicate email it redirects the user back to the form with no error message.

#If anything else happens, it redirects the user back to the form.

else:

form = CustomerForm() # An unbound form

return render(request, 'shipment/createAccount.html', { 'form': form } )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值