错误:
File "/home/soubhagya/Desktop/carrier-circle/backend/details/urls.py", line 2, in <module>
from .views import *
File "/home/soubhagya/Desktop/carrier-circle/backend/details/views.py", line 298
return {"code":402,"error":except}
^
SyntaxError: invalid syntax
代码:
try:
api = Details.get_important_links(
"OdishaGovtJobs",
"OdishaGovtJobDetails",
"state-govt-jobs/odisha-govt-jobs"
)
return JsonResponse(api,safe=False)
except:
return {"code":402,"error":except}
我正在尝试发送异常以及状态代码,但这给了我语法错误
答案 0 :(得分:2)
我假设您在函数内
您可以试试吗?这对我有用
def my_def():
try:
api = Details.get_important_links(
"OdishaGovtJobs",
"OdishaGovtJobDetails",
"state-govt-jobs/odisha-govt-jobs"
)
print ('Im a print in the try')
return JsonResponse(api,safe=False)
except Exception as e :
print ('Im in the except' )
return {"code":402,"error":e}
print (my_def())