Andrew Schultz
Andrew Schultz

Reputation: 43

Static assets for flask return 404 error when pushed to elastic beanstalk

I am running a flask application that works fine when I run it locally. When I deploy it on elastic beanstalk, all of the static assets (css, js, img) return a 404 error.

I am using jinja url_for in my template files to call the static assets (example below).

<link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/profile.css') }}">

My directory structure look like this:

/myapplication
    /config
    /webapp
        /static
            /css
                style.css
                profile.css
            /js
                profile.js
        /templates
            layout.html
            profile.html
            login.html
        views.py
        __init_.py
    application.py

Any idea why this will not load on elastic beanstalk?

Upvotes: 4

Views: 922

Answers (1)

manychairs
manychairs

Reputation: 149

One possible issue: Elastic Beanstalk will match your local permissions to the deployed app. Your files may be owner/group readable/writable which is fine for local testing, but then they will not be viewable on a web server by an outside user.

I had this same problem, but after I ran a chmod 664 on all my static files, they were now visible in my deployed app.

Upvotes: 4

Related Questions