【问题标题】:static stylesheet with google app engine带有谷歌应用引擎的静态样式表
【发布时间】:2013-03-03 13:44:15
【问题描述】:

我是新开发的,所以请耐心等待:)

我决定用 jetstrap(bootstrap 的可视化设计器)设计我的网站,下载 html,然后用 python 编程后端并将其上传到谷歌应用引擎。

当我从 jetstrap 下载文件时,我有一个包含我的 html 的文件夹和一个名为 assets 的文件夹,里面有 3 个文件夹。 CSS、图片、js。

如果我用浏览器打开 html,我可以看到我设计的网站。但是如果我用 python 渲染它并在 localhost 上打开它,我会看到它没有任何 css。

我尝试将文件夹添加到 app.yamal

application: web-development-test
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /templates/assets
  static_dir: stylesheet


- url: .*
  script: main.app

libraries:
- name: jinja2
  version: latest

templates 是我的应用程序目录上的文件夹,其中包含我所有的 html 和资产,该文件夹包含 css、js 和图像。

jetstrap 的 html 的一部分是:

<link href="assets/css/bootstrap.css" rel="stylesheet">
    <style>
      body { padding-top: 60px; /* 60px to make the container go all the way
      to the bottom of the topbar */ }
    </style>

我在那里看到了 rel=stylesheet,这就是为什么我在 app.yamal 上添加 static_dir: stylesheet

我所做的几乎所有事情都来自在线教程。

提前谢谢你!

编辑: 我的应用文件夹的整个结构

google project
    app.yaml
    favicon.ico
    index.yaml
    main.py
    templates
        page1.html
        page2.html
        assets
           css
           img
           js

【问题讨论】:

  • 你能发布更多关于你的目录结构的细节吗?哪些目录位于项目的顶层,下一个等?您可能还会发现 static directory handlers 上的文档很有帮助。
  • 我用我的目录结构编辑了第一篇文章。我也会看看你给我的文件。

标签: python google-app-engine assets


【解决方案1】:

app.yaml 中的第一个处理程序表示“使目录样式表(可在应用根目录中找到)在 URL 路径 /templates/assets 中可用。”这可能与您想要的相反。试试这个处理程序:

- url: /assets
  static_dir: templates/assets

这将使得,例如,http://localhost:8090/assets/css/bootstrap.css 返回位于templates/assets/css/bootstrap.css 的文件。假设 page1.html 在 //page1 或类似位置提供服务,那应该可以满足您的需求。

【讨论】:

  • 真的非常感谢您。这解决了我的问题。正如我所说,我对此很陌生,你的评论不仅解决了它,而且让我明白我做错了什么。
  • @Tasos 我很高兴能帮上忙。接受解决您问题的答案(通过单击它们左侧的箭头)是正确的 StackOverflow 礼仪,这也鼓励其他人回答您未来的问题。 (您可能还想回到之前的问题并在那里接受答案。)
【解决方案2】:

处理程序的顺序可能会导致问题:

url: /stylesheets static_dir: 样式表 url: /.* 脚本: helloworld.application

将代替

url: /.* 脚本: helloworld.application url: /stylesheets static_dir: 样式表

【讨论】:

    【解决方案3】:

    我遇到了同样的问题。我遵循了后者的所有内容,甚至是 app.yaml 文件中的缩进错误,如 here 所示。 我修复了缩进,就是这样。

    【讨论】:

      猜你喜欢
      • 2017-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-20
      • 1970-01-01
      • 1970-01-01
      • 2011-07-19
      • 2015-05-16
      相关资源
      最近更新 更多