我是django的新手,我在views.py文件中收到了无效的语法错误。有没有办法在django中调试语法错误?当使用python manage.py runserver运行开发服务器时,我得到以下错误
Below is my views.py file:
from django.shortcuts import render
from .models import OrderItem
from .forms import OrderCreateForm
from cart.cart import Cart
#from .tasks import order_created
from django.shortcuts import render, redirect
from django.core.urlresolvers import reverse
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save()
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])
# clear the cart
cart.clear()
# launch asynchronous task
# order_created.delay(order.id)
# set the order in the session
request.session['order_id'] = order.id
# redirect to the payment
return redirect(reverse('payment:process'))
else:
form = OrderCreateForm()
return render(request,`enter code here`
'orders/order/create.html',
{'cart': cart, 'form': form}
....... ===============
{{1}}
答案 0 :(得分:0)
我没有用括号关闭render
函数。
P.S。使用Pycharm可以避免语法错误。如果语法有问题,它会立即显示给你。
答案 1 :(得分:0)
关闭渲染功能括号。 在“在此处输入代码”后添加反斜杠