gpt4 book ai didi

python - 使用 session 的Django View 中 “def”的语法错误

转载 作者:行者123 更新时间:2023-12-03 08:15:51 27 4
gpt4 key购买 nike

它位于Django项目中的应用程序中,位于该应用程序的views文件中。该应用程序安装在settings.py中,但在调用 View 之前会引发错误。

我在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>")

最佳答案

def CouponList(req):
c = Coupon.objects.all()
return render(req,'coupon_list.html',{'title':'Coupons','coupons':c})
^
|
You are missing this bracket

关于python - 使用 session 的Django View 中 “def”的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17151503/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com