0

I've recently reorganised my project folders and I've put my static folder inside a new view folder.

/view
- /static
- /templates
main-controller.py

When I call the Flask app in main-controller.py I define the new view folder in the constructor:

app = Flask(__name__, root_path='view/')

When I start the Flask server it renders the template page inside templates however doesn't render anything from the static folder, receiving page errors like:

Failed to load resource: style.css:1 
the server responded with a status of 404 (NOT FOUND)

Failed to load resource: script.js:1 
the server responded with a status of 404 (NOT FOUND)

Which are called in session.html with:

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

and

<script type="text/javascript"  src="{{ url_for('static', filename='script.js') }}"></script>

Why is it failing to find the static folder but finding the templates folder fine?

James
  • 1
  • 2
  • Hi where is your styles folder within static? I don't see that listed, also is your script.js within your static folder? – Nathan Feb 04 '19 at 17:36
  • Also what is the web inspector says ? which link it tries to reach and got `404` ? – Mostafa Hussein Feb 04 '19 at 17:37
  • @NathanWright script.js is in static and the style.css is in the styles folder in static – James Feb 04 '19 at 17:40
  • @MostafaHussein "GET http://127.0.0.1:5000/static/script.js net::ERR_ABORTED 404 (NOT FOUND)" and "GET http://127.0.0.1:5000/static/styles/style.css net::ERR_ABORTED 404 (NOT FOUND)" – James Feb 04 '19 at 17:44
  • 1
    Can you specify your static path when you initialize your flask app: app = Flask(__name__, static_folder='/static') – Nathan Feb 04 '19 at 17:45
  • @NathanWright Yeah but that doesn't work either – James Feb 04 '19 at 17:46
  • ok I don't think you're running in debug mode based on the code above. So can you make that change specifying the static path, then restart the server and navigate to your webpage and see if the issue persists? – Nathan Feb 04 '19 at 17:48
  • @NathanWright Yeah I did, added the parameter to the constructor app = Flask(__name__, template_folder='view/templates', static_folder='view/static'), restarted the server and got the same problem – James Feb 04 '19 at 17:50

0 Answers0