0

I have a file test1.py. I am using web.py to display it in a webpage.

    import web

    urls = ('/', 'hello','/bye', 'bye')

    app = web.application(urls, globals(), True)

    class hello:
      def GET(self):
         return """<html>
         <head>
         </head>
          <body>
            <img src="smile.png" alt="SAP Logo" width="500px" height="100px"/>
           </body></html>"""

However, when run it will display:

127.0.0.1:59558 - - [28/Sep/2015 15:52:32] "HTTP/1.1 GET /" - 200 OK
127.0.0.1:59558 - - [28/Sep/2015 15:52:32] "HTTP/1.1 GET smile.png" - 404 Not Found

Image is placed in Desktop.

2
  • If the image is placed on the desktop, does that mean that the servers' folder root is also on the desktop? Commented Sep 28, 2015 at 8:07
  • Where have you told web.py how to serve your image from the desktop? Commented Sep 28, 2015 at 8:09

1 Answer 1

2

Create a "static" folder in your project root, copy your "smile.png" to that folder. Now change the src value of the img tag:

<img src="/static/smile.png" alt="SAP Logo" width="500px" height="100px"/>

You should see your smile.png in the brower now, for more info on serving static files in web.py, go visit "http://webpy.org/cookbook/staticfiles".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.