2016-12-12 55 views
-1

我是新來的Django,我得到一個無效的語法錯誤在views.py文件。有沒有一種方法可以在django中調試語法錯誤?當運行使用python manage.py runserver命令我提示以下錯誤:無效的語法(views.py,第34行)

開發服務器
=============== 
SyntaxError at/
invalid syntax (views.py, line 34) 
Request Method: GET 
Request URL: http://localhost:8000/ 
Django Version: 1.8.5 
Exception Type: SyntaxError 
Exception Value:  
invalid syntax (views.py, line 34) 
Exception Location: /home/arajguru/training/mycode/myshop/orders/urls.py in <module>, line 2 
Python Executable: /home/arajguru/training/mycode/env/myshop/bin/python 

....... ===============

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} 
+0

對於除您以外的任何人,第34行並不意味着很多,請嘗試在提問時創建[mcve]。 – Sayse

回答

0

我沒有用括號關閉render函數。

P.S.使用Pycharm來避免語法錯誤。如果語法有問題,它會立即顯示給你。

+0

非常感謝。 –

0

關閉渲染函數括號。 在「在此處輸入代碼」後添加反斜槓\「