I'm having trouble with displaying static files on my Flask website and would really appreciate some help since I don't have much experience in web development.
Sorry if I'm not explaining clearly, but here's the issue:
Problem: Whenever I try to load static files (specifically an mp4 video) on my Flask site, I constantly get a 404 error. Despite checking file paths and permissions, I can't seem to fix the problem. I know there are many similar questions about serving static files, but the solutions provided haven't worked for me, especially since I just want to add a background video to my site.
Here are the relevant code snippets from my Flask app:
Setting up Flask application
app = Flask(__name__)
app._static_folder = '/static'
HTML/CSS for background video
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Barcode Wall Control Server</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="670508081314131506172752495449574a060b170f0656">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
@media screen and (max-height: 450px) {
.sidebar {padding-top: 15px;}
.sidebar a {font-size: 18px;}
}
#mainContent {
padding: 20px;
}
/*Video Background */
#backVideo {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -1;
overflow: hidden;
}
</style>
</head>
<body style="background-color: #b8b7b74f;">
<video autoplay loop muted id="backVideo">
<source src="{{url_for('static', filename='barcode.mp4')}}" type="video/mp4">
</video>
</body>
When I try to load the static files, my terminal shows this error message:
[15/May/2024 14:38:46] "GET /static/barcode.mp4 HTTP/1.1" 404
PS. The HTML code works fine when run without the server.