Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

External CSS Style sheet doesn't work when running on GAE

I have main.html that links to web.css and when I run the main file it runs fine with the CSS but when I run the whole thing on google app engine, it doesn't apply the CSS. From the GAE logs I get

INFO     2012-05-10 01:58:46,526 dev_appserver.py:2891] "GET /web.css HTTP/1.1" 404 -
INFO     2012-05-10 01:58:46,540 dev_appserver.py:2891] "GET /favicon.ico HTTP/1.1" 200 -

This is in my html file

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="web.css"/>
    </head>
    <body>
        <h1> Hi </h1>
    </body>
</html>

And this is my code

import os
import webapp2
import jinja2
import re
from datetime import datetime
from google.appengine.ext import db
from utility_functions import valid_username, valid_password, valid_email

class Handler(webapp2.RequestHandler):    
    def render(self, link, values={}):
        je = jinja2.Environment(autoescape=True, loader=jinja2.FileSystemLoader(
            os.path.join(os.path.dirname(__file__), 'templates')))

        template = je.get_template(link)
        self.response.out.write(template.render(values))        


class MainPage(Handler):
    def get(self):
        self.render('main.html')


handlers = [('/', MainPage)]
app = webapp2.WSGIApplication(handlers, debug=True)
like image 858
petabyte Avatar asked Dec 20 '22 22:12

petabyte


2 Answers

For anyone else that stumbles upon this question, static files should be declared with a static file handler. For example, this serves a directory called css, which maps the directory css in the root of your application directory to a publicly available css directory at the root of your appspot domain:

- url: /css
  static_dir: css
like image 151
Dan Holevoet Avatar answered Dec 23 '22 11:12

Dan Holevoet


add this to your app.yaml:

- url: /web.css
  static_files: web.css
  upload: web.css
like image 35
lenik Avatar answered Dec 23 '22 12:12

lenik