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))

I'm getting

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

And line 41 is the last line.

Where am I wrong?

Thanks.

Answers


You can't use a comment as an empty statement, you should use pass if you want to have an explicit else that does nothing.

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

Since there's no statement, just a comment in the else in your code, python thinks the return is supposed to be the content of the else and gives an intentation error.


Need Your Help

Bulk insert failing on access denied to file with domain account

sql-server

I've got a sql server 2014 that is trying to do a bulk insert into a table that is initiated from a stored procedure. The bulk insert refers to a network file path. I've set the share to allow all

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.