2016-03-26 63 views
-2

我不知道什麼是錯,此代碼,但得到「類型錯誤:‘功能’對象不是可迭代」 它的正確適用於「/ FILESTREAM」,但不是「/ ALLFILE」爲什麼得到TypeError:'function'對象不可迭代?

Python代碼

@app.route('/allfile') 
@login_required 
def allfile(): 
    fileStream = models.File.select().limit(100) 
    return render_template('filestream.html', filestream=filestream) 

@app.route('/filestream') 
#@app.route('/filestream/<username>') 
def filestream(username=None): 
    template = 'fileStream.html' 
    if username and username != current_user.username: 
     user =  models.User.select().where(models.User.username**username).get() # the ** is  the "like" operator (non-case sensitive comparison) 
     filestream = user.files.limit(100) 
    else: 
     filestream = current_user.get_filestream().limit(100) 
     user = current_user 
    #if username: 
     #template = 'user_stream.html' 
    return render_template(template, filestream=filestream, user=user) 

HTML代碼

{% extends "layout.html" %} 

{% block content %} 
{% for file in filestream %} 
    <article> 
    <h2> 
     <a href="{{ url_for('filestream', username=file.user.username) }}"> 
     {{ file.user.username }} 
     </a> 
    </h2> 
    <i class="clock"></i> 
    <time data-time="{{ file.timestamp }}" }}"> 
     {{ file.timestamp.strftime('%Y-%m-%d %H:%M:%S') }} 
    </time> 
    <!-- <a href="{{ url_for('view_file', file_id=file.id) }}"  class="view">View</a>--> 
    <div class="file"> 
     <a href="{{ file.path}}"</a> 
     <img src="{{ file.path }}" alt=""  style="width:521px;height:512px;"> 
    </div> 
    </article> 
{% endfor %} 
{% endblock %} 
+0

提供完整的追溯請 –

+0

也是你的其他python代碼... – Signal

回答

1

裏面allfile()你定義一個名爲一個局部變量,大寫字母S.但您傳遞給模板的是filestream,小寫字母S;這不是在本地定義的,所以Python使用模塊級名稱來引用filestream()處理程序。

請確保您的函數中使用的是一致的大寫。

相關問題