繁体   English   中英

Python缩进问题:预期缩进块

[英]Python indentation issue: Expected an indentation block

def process_health_case(request):
    about = request.POST['about']
    details = request.POST['narrative_text']
    image=request.FILES['image_scan']
    connection = Connection('mongodb://sbose78:PASSWORD@staff.mongohq.com:10068/BOSE')
    if images:
        db=connection['BOSE']
        fs=gridfs.GridFS(db)
        fs.put(image,filename="image_scan2")
    else:
        #nothing
    return render_to_response('home/new_narrative.html',{ }, context_instance=RequestContext(request))

我越来越

expected an indented block (views.py, line 41)

第41行是最后一行。

我哪里错了?

谢谢。

您不能将注释用作空语句,如果您希望拥有一个不执行任何操作的显式else,则应使用pass

if images:
    db=connection['BOSE']
    fs=gridfs.GridFS(db)
    fs.put(image,filename="image_scan2")
else:
    pass
return ....

由于没有语句,仅在代码的else中添加了注释,python认为return应该是else的内容,并给出一个意图错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM