I am doing my final project and in my website I wish to have an image as the background and I have saved that image in a file on my workspace. The body background property is not supported in HTML5 so, I am using the css background image property but the image doesn't load. The console shows an error of 404, file not found. I have tried both of saving the image in the same directory as my html file and in some other directory and have provided the proper url(path) in the css url. Any suggestions why this may not be working? Also, I have used the URL like (../project/image.jpg), (/project/image.jpg). Tried a number of ways , none works. How can I have background images uploaded in my jinja supported html fileson cloud9 ?
You need to store (and serve) the image from the
static directory or a subdirectory thereof.
static is the default
static_folder) when the app object is created and configured here
app = Flask(__name__) in application.py. You can refer to this doc for more detailed information about the application object constructor. For instance:
static_folder – the folder with static files that should be served at static_url_path. Defaults to the 'static' folder in the root path of the application.
(I eventually ended up at the flask documentation after every hit for "flask serve image" mentioned "static". Doh! It's similar to "public_html" or "public" in apache.)
Suggest you create an
images or similar subdirectory of
static that contains
image.jpg. Then the
background-image: directive will be `url('/static/images/image.jpg').
Make sure you can access the image from the address bar as with:
If you cannot access it from the address bar, the flask server will not be able to access it either. It might save troubleshooting time.