簡體   English   中英

Flask render_template() 在 Azure Web 應用程序中不起作用

[英]Flask render_template() not working in Azure Web App

我正在嘗試調試我的 Flask 應用程序。 我通過 Git-Hub 部署將它部署在 Azure Web App 上。 該代碼在 localhost 上運行良好,可以渲染表格和所有內容,但是,當部署到 Azure 時,除了帶有表格的 render_template() 之外,一切正常。

這就是我的意思:

# This is my view route in quess_blueprint.py
@quess_blueprint.route('/view_all_quests')
def view_all_quests():
    limit = 10
    quests_collection = mongo.db.quests
    offset = int(request.args['offset'])
    quests_table = list(quests_collection .find({}).sort('_id', mongo.ASCENDING).limit(limit)))
    print(quests_table) # I see the result in the Console so i know it's getting the data
    next_url = BASE_ROUTE+'productivity_suite/'+route_name+'?offset=' + str(offset + limit)
    prev_url = BASE_ROUTE+'productivity_suite/'+route_name+'?offset=' + str(offset - limit)
    return render_template('quests/quests_table.html', quests_table=quests_table, next_url=next_url, prev_url=prev_url)
# This is my html for quests_table.html
.
.
.
    </thead>
    <tbody>
        {% for quest in quests %}
        <tr>
          <td data-label="Quest Name">{{quest.quest_name}}</td>
          <td data-label="Quest Priority">{{quest.quest_priority}}</td>
          <td data-label="Due Date">{{quest.due_date}}</td>
          <td data-label="Completed Date">{{quest.completed_date}}</td>
          <td data-label="Quest Elder">{{quest.quest_elder}}</td>
          <td data-label="Primary Assigned">{{quest.primary_user}}</td>
          <td data-label="Secondary Assigned">{{quest.secondary_user}}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>

當我在本地運行它時,我可以看到print(quests_table)的結果,並且代碼呈現了 quests 表。

但是,當我部署到 Azure 並查看日志 Stream 時,我仍然可以看到print(quests_table)的結果,並且代碼呈現 ZFC35FDC70D5FC69D269883A822EZC7 中的表格,但沒有模板,表格For 循環。

我不確定為什么 Azure 沒有正確讀取 For 循環。

我已經嘗試了很多事情,比如更改模板,將列表變成 dataframe 然后 to_html 仍然不起作用。 從字面上看,其他一切都有效。

任何幫助,將不勝感激。 謝謝你。

故障排除步驟:

  1. 確保您收到 http 響應。

    按 F12,檢查 http 請求。

  2. 如果得到響應,請檢查返回的結果是否是您想要的。

  3. 如果得到 null 或空結果,請檢查 sql 連接字符串。

  4. 如果您嘗試以上方法都沒有問題,請檢查您本地的python版本,flask版本,並嘗試創建與本地版本相同的azure webapp。 您也可以嘗試創建一個容器應用程序。 如果不修改代碼一切正常,可能是azure webapp pyhton平台的具體版本有bug。

  5. 並建議您檢查門戶上的應用程序日志,如果沒有錯誤,您可能需要通過在門戶上提出支持票來聯系 MSFT

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM