Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In Flask, the background image can be set in the HTML template file using CSS. Here are the steps to set a background image:

  1. Save the image file in the static folder of your Flask application.

  2. Create a CSS file in the static folder or add the CSS code in the HTML file.

  3. In the CSS code, set the background-image property to the path of the image file:

body {
  background-image: url('/static/image_name.jpg');
}
  1. Link the CSS file to the HTML template file or add the CSS code within a <style> tag in the head section of the HTML file.
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
  </head>
  <body>
    ...
  </body>
</html>

Note: Make sure to use the correct path to the image and the correct filename in the CSS and HTML code.