簡體   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