Forums

can't link css

Hi I'm new to web development and I have written a simple blog app in webapp2 framework but my css link seems to be broken and not working.here is some detail

my files: /blog.py

/templates/blog_front.html

/static/blog.css

and for linking css I use <link type="text/css" rel="stylesheet" href="/static/blog.css" /> in my blog_front.html file

Hi Aramik,

It looks like webapp2 is mainly used on Google App Engine and as such it doesn't have a built in handler for static files. The suggestions that I did find won't work on PythonAnywhere because we serve the wsgi application for you rather than getting you to start your own server. You could write a request handler that directly returned your css.

class CSSHandler(webapp2.RequestHandler):
    def get(self, *args, **kwargs):
        with open('/home/aramik/static/blog.css') as f:
            response = webapp2.Response(f.read())
            response.content_type = 'text/css'
            return response

app = webapp2.WSGIApplication([
    (r'/static/blog.css', CSSHandler),

We are currently working on making this kind of stuff unnecessary. Static files will be served by the web server in the near future.

Hi hansel I tested this approach but it seems it isnt working even i tried to get my css directly from typing url of its handler in brower but no luck I get this error

Traceback (most recent call last): File "/home/aramik/.local/lib/python2.6/site-packages/webapp2.py", line 1547, in call return response(environ, start_response) TypeError: 'str' object is not callable

Hi aramik, sorry. My bad. I wasn't reading the webapp2 code examples properly. You need to return a response object. I've edited my post to include code that should work. I've at least tested it in a console this time :-)

+1 for testing...☺

I know! Who would have thought...

tnx very much, its working ;)