这是在Django项目的应用程序中,该应用程序的视图文件中。该应用程序安装在settings.py中,但它会在调用该视图之前抛出该错误。
我在CouponForm的“def”中的“f”处收到错误,它说这是一个SyntaxError,但我无法解决问题。 urlconf仅引用manageCoupons函数。 在此先感谢您的帮助!
views.py:
from models import Coupon
from django.shortcuts import render
from django.http import HttpResponse
def CouponList(req):
c = Coupon.objects.all()
return render(req,'coupon_list.html',{'title':'Coupons','coupons':c}
def CouponForm(req1):
if 'name' in req1.GET and 'desc' in req1.GET:
name1 = req1.GET['cname']
desc = req1.GET['desc']
c = Coupon(name=name1, description=desc)
c.save()
success = True
else:
success = False
return render(req1,'coupon.html',{'title':'New Coupon','success':success,})
def CouponDelete(req2):
if 'name' in req2.GET:
name1 = req2.GET['name']
c = Coupon.objects.filter(name=name1)
c.delete()
success = True
else:
success = False
return render(req2,'coupon_delete.html',{'title':'Delete Coupon','success':success}
def manageCoupons(request):
if 'passwrd' in request.GET:
psswrd = request.GET['passwrd']
if psswrd == 'password0':
return CouponList(request)
elif psswrd == 'password1':
request.session["function"] = 'cform'
return CouponForm(request)
elif psswrd == 'password2':
request.session["function"] = 'cdelete'
return CouponDelete(request)
elif "function" in request.session:
if request.session["function"] == 'cdelete':
return CouponDelete(request)
elif request.session["function"] == 'cform':
return CouponForm(request)
else:
return HttpResponse("<a href='/'>Home</a>")
答案 0 :(得分:3)
def CouponList(req):
c = Coupon.objects.all()
return render(req,'coupon_list.html',{'title':'Coupons','coupons':c})
^
|
You are missing this bracket
答案 1 :(得分:1)
您在这一行缺少)
:
render(req2,'coupon_delete.html',{'title':'Delete Coupon','success':success}
应该是:
render(req2,'coupon_delete.html',{'title':'Delete Coupon','success':success})