简体   繁体   English

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

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

I'm trying to debug my Flask app.我正在尝试调试我的 Flask 应用程序。 I have it deployed on Azure Web App via Git-Hub deployment.我通过 Git-Hub 部署将它部署在 Azure Web App 上。 The code works perfectly fine on localhost, renders the table and everything, however, when deployed to Azure, everything works fine EXCEPT for render_template() with a table.该代码在 localhost 上运行良好,可以渲染表格和所有内容,但是,当部署到 Azure 时,除了带有表格的 render_template() 之外,一切正常。

Here's what I mean:这就是我的意思:

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

When I run this locally, I can see the result of the print(quests_table) and the code renders the quests table.当我在本地运行它时,我可以看到print(quests_table)的结果,并且代码呈现了 quests 表。

However, when I deploy to Azure, and look at the Log Stream, I still can see the result of the print(quests_table) and the code renders the html template, with the table head, buttons, etc, but without the table body from the For Loop.但是,当我部署到 Azure 并查看日志 Stream 时,我仍然可以看到print(quests_table)的结果,并且代码呈现 ZFC35FDC70D5FC69D269883A822EZC7 中的表格,但没有模板,表格For 循环。

I'm not sure why Azure is not reading the For Loop correctly.我不确定为什么 Azure 没有正确读取 For 循环。

I've tried so many things like changing the template, making the list into a dataframe and then to_html and still doesn't work.我已经尝试了很多事情,比如更改模板,将列表变成 dataframe 然后 to_html 仍然不起作用。 Literally everything else works.从字面上看,其他一切都有效。

Any help would be appreciated.任何帮助,将不胜感激。 Thank you.谢谢你。

Troubleshooting Steps:故障排除步骤:

  1. Make sure you have got http response.确保您收到 http 响应。

    Press F12, check the http request.按 F12,检查 http 请求。

  2. If get response, check if the returned result is what you want.如果得到响应,请检查返回的结果是否是您想要的。

  3. If get null or empty result, check the sql connectionstrings.如果得到 null 或空结果,请检查 sql 连接字符串。

  4. If you try the above methods and there is no problem, check your local python version, flask version, and try to create the same azure webapp as the local version.如果您尝试以上方法都没有问题,请检查您本地的python版本,flask版本,并尝试创建与本地版本相同的azure webapp。 You can also try to create a containner app.您也可以尝试创建一个容器应用程序。 If everything is normal without modifying the code, there may be a bug in the specific version of the azure webapp pyhton platform.如果不修改代码一切正常,可能是azure webapp pyhton平台的具体版本有bug。

  5. And suggest you check application logs on portal, if no error, you maybe need contact MSFT by raising a support ticket on portal .并建议您检查门户上的应用程序日志,如果没有错误,您可能需要通过在门户上提出支持票来联系 MSFT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM