我需要根据一个变量过滤一个查询,但前提是这个变量不为空...以下是我尝试过的方法: rows = Attendance.objects.filter(type= the_type if the_type= "" else '*') 问题出在我试图删除的那部分else '*'中,但它不会工作,因为它需要在ternary operator中使用else之后的if,我也尝试了else pass,但它给了我一个错误编辑 我可以在查询集之外使用if,但是I have more than on
我只想在web服务启动时执行某些代码一次。我本想使用void Application_Start(object sender, EventArgs e),但我的代码中已经这样做了我得到的异常Request is not available in this context似乎对象可能还不存在,因为应用程序才刚刚启动,并没有处理请求。