【问题标题】:Issues rendering static files on Pythonanywhere在 Pythonanywhere 上呈现静态文件的问题
【发布时间】:2017-08-24 20:59:05
【问题描述】:

我正在尝试使用 Pythonanywhere 托管 Flask 应用程序,但在渲染图像时遇到了问题。我很确定我已正确导航到它,但它仍然无法找到并显示它。

我的网页代码在这里:

{% extends "base.html" %}


{% block content %}

<div class="media">
  <div class="media-left media-top">
    <a href="#">
      <img class="media-object" height = "130" width = "130"       src="/home/jamesk93/mysite/app/static/images/profilepic.jpg" alt="">
</a>
  </div>

 <div class="media-body">
    <h3 class="media-heading"></h3>
    <p>University Attended: </p>
    <p> </p>
    <p> </p>
    <p></p>
    <p></p>
  </div>
</div>


{% endblock %}

我的应用程序如下所示:

from flask import Flask, render_template
app = Flask(__name__)


@app.route('/')
@app.route('/home')
def homepage():
    return render_template("home.html")


@app.route('/education')
def education():
    return render_template("education.html")

@app.route('/employment')
def employment():
    return render_template("employment.html")

if __name__ == "__main__":
    app.run()

我做了一些研究,我认为这是因为我需要为我的静态文件夹提供服务,但我不确定如何去做,所以这就是我在这里询问的原因(如果这甚至是问题)

【问题讨论】:

    标签: flask pythonanywhere


    【解决方案1】:

    在 Pythonanywhere 的 Web 选项卡上,您可以找到静态文件部分。

    在那里添加一个 URL 和目录。

    在我的应用程序中,我定义了两个,如下所示:

    URL              Directory
    /static/         /home/user/project/app/static/
    /uploads/        /home/user/project/app/uploads/
    

    更多细节可以在 Pythonanywhere 帮助文档中找到: https://help.pythonanywhere.com/pages/StaticFiles

    【讨论】:

      猜你喜欢
      • 2020-11-18
      • 2022-07-29
      • 1970-01-01
      • 2012-04-20
      • 2012-01-21
      • 2020-11-06
      • 2020-11-24
      • 2019-07-14
      • 2016-11-13
      相关资源
      最近更新 更多