2012-09-08 45 views
1
def process_health_case(request): 
    about = request.POST['about'] 
    details = request.POST['narrative_text'] 
    image=request.FILES['image_scan'] 
    connection = Connection('mongodb://sbose78:[email protected]: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)) 

我越來越Python的縮進問題:預期的縮進塊

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

和線路41是最後一行。

我在哪裏錯了?

謝謝。

回答

6

您不能使用註釋作爲空白語句,如果您希望有一個明確的else,則不應該使用pass

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

既然沒有發言,只是在你的代碼else評論,蟒蛇認爲return應該是else的內容並給出了一個intentation錯誤。

+0

工作!非常感謝你Joachim! :) – sbose

+0

無論如何,這裏的else語句完全沒有必要。如果你所做的只是「通過」,你應該忽略整個條款。 –