它位于Django项目中的某个应用程序中,位于该应用程序的views文件中。该应用程序安装在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>")
呼啦一阵风
子衿沉夜
相关分类