2

My static files are all returning a 404 error.

below is the structure:

-root
   -web
      -static
        -css
          -main.css
      -templates
         base.html
         home.html

      app.py

I have a static and templates folder in the same directory as the app. Below is the code for app.py:

class FrontEnd(Flask):
    jinja_options = Flask.jinja_options.copy()
    jinja_options.update(dict(
        block_start_string='{%',
        block_end_string='%}',
        variable_start_string='[[',
        variable_end_string=']]',
        comment_start_string='{#',
        comment_end_string='#}',
    ))

app = FrontEnd(__name__)

@app.route('/')
def index_page():
    details = {"name" : "mark", "surname" : "boleigha", "occupation" : "programmer"}
    view_data = { "page_name" : "this is the homepage", "title" : "Home", "details" : details }
    return render_template("home.html", **view_data)

below is the code for base.html:

   <head>
       <title>[[title]] | Recruitr</title>

       <link rel="stylesheet" href="[[ url_for('static', filename='css/bootstrap.min.css') ]]"  />
   </head>
   <body>
      {% block content %}

      {% endblock content %}
   </body>
</html>

below is the code for home.html:

{% extends "base.html" %}

{% block content %}
  #body here
{% endblock content %}

please note that i use [[ in the jinja templates to avoid confusions with curly braces as i intend to use a javascript framework.

All CSS files are in static folder. Template render but without styling as static files are suddenly returning 404 error.

everything was working fine until i rebooted. below is screenshot of my terminal and file tree: screenshot

file_tree

  • 1
    Possible duplicate of [Flask, Keep getting 404 serving static files using send\_static\_file](https://stackoverflow.com/questions/27596297/flask-keep-getting-404-serving-static-files-using-send-static-file) – LenglBoy Apr 05 '18 at 12:33
  • Do you have configured Flask to serve static files or any nginx/apache/… proxy to do it instead? From what we can read here anything that is not `your-domain.tld/` will result in a 404 error. – Benoît Latinier Apr 05 '18 at 12:34
  • We have no idea on where your static files are, and what URL Flask is seeing from you. Please provide additional information. – Giacomo Catenazzi Apr 05 '18 at 12:46
  • Please show your html as well – OneCricketeer Apr 05 '18 at 13:08
  • i have edited to show the directory structure – Mark Boleigha Apr 05 '18 at 13:08
  • Still it's not clear about your director structure. In your index_page returns `home.html` but where is home.html in your modified question? I suggest you to take screenshot of your ide folder and file tree view, Then attache it here. Also it will be great if you add your home.html and base.html and screenshot of your terminal. Thanks – Raja Simon Apr 05 '18 at 13:31
  • i have added and done all asked. please help. it is driving me nuts – Mark Boleigha Apr 05 '18 at 14:43
  • Are you missing the "web" folder? – tomasantunes Apr 05 '18 at 16:15

0 Answers0