参数未加载css

时间:2017-08-17 04:42:59

标签: python flask

我遇到了这个奇怪的问题。

我将Flask定义如下:

blog = Blueprint(
    'blog',
    __name__,
    template_folder='templates',
    static_folder='static'
)
@blog.route("/post")

def post():
    return render_template('post.html')

http://localhost:5000/blog/post正确加载css,但是,如果我向post()添加了参数,则无法加载css。

@blog.route("/post/<fileid>")
def post(fileid):
    page = download_file_from_google_drive(fileid)
    page = Markup(markdown.markdown(page))
    return render_template('post.html', page)

post.html使用模板。看起来如下:

{% extends "base.html" %}


{% block content %}

    <!-- Page Header -->
    <header class="masthead" style="background-image: url('static/img/post-bg.jpg')">
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-10 mx-auto">
            <div class="post-heading">
              <h1>Man must explore, and this is exploration at its greatest</h1>
              <h2 class="subheading">Problems look mighty small from 150 miles up</h2>
              <span class="meta">Posted by
                <a href="#">Start Bootstrap</a>
                on August 24, 2017</span>
            </div>
          </div>
        </div>
      </div>
    </header>

    <!-- Post Content -->
    <article>
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-10 mx-auto">

            {{ page }}

          </div>
        </div>
      </div>
    </article>

    <hr>

{% endblock %}

我的BluePrint设置有问题吗?

1 个答案:

答案 0 :(得分:1)

您的Python代码完全没有问题。

但是,看起来您正在使用当前页面的相对路径加载CSS,这意味着如果您在页面上使用URL = #include <stdio.h> #include <math.h> void calcRange(short); /* print min and max of data types */ int main() { printf("CHAR:\n"); calcRange(sizeof(char)); printf("SHORT:\n"); calcRange(sizeof(short)); printf("INT:\n"); calcRange(sizeof(int)); printf("LONG:\n"); calcRange(sizeof(long)); } /* calculates the range of a data type given it's size in bytes */ void calcRange(short size) { double lower = -pow(2, size*8 - 1); double upper = pow(2, size*8 - 1) - 1; // change rightmost sub double uUpper = pow(2, size*8) - 1; // change rightmost sub printf("The signed range for this data type is (%.0f , %.0f)\n", lower, upper); printf("The unsigned range for this data type is (0, %.0f)\n\n", uUpper); } ,那么您的CSS(嗯,任何东西,其路径指定为相对路径)如下所示加载到当前路径:/blog/post/<fileid>

您应该尝试使用绝对路径加载CSS。这看起来像这样:/blog/post/<fileid>/<whatever>

因此,您唯一需要更改的是/post.css模板。

如果这不能解决您的问题,请打开开发人员控制台并查看输出。如果你足够聪明,你可以自己找出答案。