1

I have the image files uploaded to my cloud9 IDE, the code only spits out the text added to go with the images, but won't show the images. How can I set it up so that the images will show?

I have tried looking at code online for HTML that do a similar function but none of them have been working in my situation. I am not using a static file in this process, The process I need to follow requires me to build the html code into the python code itself. As the code shows, it needs to be accessible in cloud9 IDE and I don't have access to the template folder where Flask would look for static templates for HTML code. This is a different issue.

    #import statements
    import os
    from flask import Flask
    app = Flask(__name__)
    @app.route("/")
    @app.route('/moreHTML')
    def hello_index():
        my_reply = pop_head()
        my_reply += "<p></p>"
        my_reply += pictures()
        return my_reply
    def pictures():
        """inserts photos into website via HTML"""
        photo = "<!DOCTYPE html> "
        photo += '<img src="1.jpg" alt="Flying Kites" width="300"  height="300"> '
        photo += '<br>'
        photo += 'alt="A funny dog sitting on the grass.">'
        return photo
    def popEnd():#
        """Ends the HTML code"""
        end_data = "</body>"
        end_data += "</html>"
        return end_data
    def pop_head():
        """puts together the website title"""
        head_data = "<!DOCTYPE html> "
        head_data += "<head> "
        head_data += "<title>A Website</title>"
        head_data += "<style>" + getStyle() + "</style>"
        head_data += "</head>"
        head_data += "<body>"
        return head_data
    def getStyle():
        """puts together the style used in website title"""
        my_style = "table,td {"
        my_style += "border: 12px solid #130;"
        my_style += "}"
        return my_style
    host = '0.0.0.0'
    if __name__ == '__main__':
        app.debug = True
        port = int(os.environ.get("PORT", 8080))
        app.run(host=host, port=port) 
  • Possible duplicate of [Where does flask look for image files?](https://stackoverflow.com/questions/28207761/where-does-flask-look-for-image-files) – Jonathan Feenstra Oct 10 '19 at 19:33
  • I am not using a static file in this process, The process I need to follow requires me to build the html code into the python code itself. As the code shows above, it needs to be accessible in cloud9 IDE and I don't have access to the template folder where Flask would look for static templates for HTML code. This is a different issue. – William Hoffman Oct 10 '19 at 20:41
  • I see, I removed my duplicate flag. Usually, you would put the image somewhere in the static folder and use `url_for`. You could even hardcode it and put "static/" before the filename in the `src` attribute. If you are unable to access the static folder, the only way I can think of is by using a direct URL to the image. – Jonathan Feenstra Oct 10 '19 at 20:52

0 Answers0