简体   繁体   English

带有Google App Engine的静态样式表

[英]static stylesheet with google app engine

I am new on developing, so please be patiente :) 我是开发的新手,所以请耐心:)

I decide to design my site with jetstrap (visual designer for bootstrap), download the html and then programming the back-end with python and upload it to google app engine. 我决定使用jetstrap(引导程序的可视设计器)设计网站,下载html,然后使用python编程后端并将其上传到Google App Engine。

When I download the files from jetstrap, I have a folder with my html and a folder named assets with 3 folders inside. 当我从jetstrap下载文件时,我有一个带有html的文件夹和一个名为Assets的文件夹,其中有3个文件夹。 CSS, images, js. CSS,图片,js。

If I open the html with a browser, I can see the site like I design it. 如果使用浏览器打开html,则可以像设计网站一样看到该网站。 But if I render it with python and open it on localhost, I see it without any css. 但是,如果我使用python渲染它并在localhost上打开它,我将看到它没有任何CSS。

I try to add the folder to app.yamal 我尝试将文件夹添加到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 is the folder on my application dir with all my htmls and assets the folder with css, js and images. 模板是我所有HTML和资产的应用程序目录上的文件夹,其中包含CSS,JS和图像。

A part of html from jetstrap is: 来自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>

I see the rel=stylesheet there, that's why I add on app.yamal the static_dir: stylesheet 我在那里看到rel = stylesheet,这就是为什么我在app.yamal上添加了static_dir:stylesheet

Almost everything I have done, are from online tutorials. 我几乎所做的所有事情都是来自在线教程。

Thank you in advance! 先感谢您!

Edit: The whole structure of my app folder 编辑:我的应用程序文件夹的整体结构

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

The first handler in your app.yaml says "make the directory stylesheets (to be found in the app root) available at the URL path /templates/assets." app.yaml中的第一个处理程序说:“使目录样式表(在应用程序的根目录中找到)可在URL路径/ templates / assets中使用。” This is probably the reverse of what you want. 这可能与您想要的相反。 Try this handler instead: 尝试使用以下处理程序:

- url: /assets
  static_dir: templates/assets

That will make it so that, for example, http://localhost:8090/assets/css/bootstrap.css returns the file at templates/assets/css/bootstrap.css . 这样一来,例如, http://localhost:8090/assets/css/bootstrap.css将文件返回到templates/assets/css/bootstrap.css Assuming page1.html is served at / or /page1 or similar, that should do what you want. 假设在//page1或类似位置提供page1.html,这应该可以满足您的要求。

The order of handler might cause the problems: 处理程序的顺序可能会导致问题:

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

will work instead of 将代替

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

I had the same problem. 我有同样的问题。 I followed everything to the latter even the indentation error in the app.yaml file as can be seen here . 我也跟着一切后者甚至压痕误差在app.yaml文件中可以看出这里 I fixed the indentation and that was it. 我修复了缩进,仅此而已。

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

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