0

I'm aware that once I have everything up and running on a production server, nginx or apache are supposed to be serving static assets instead of Flask. In the interest of getting started quickly though, I'm running into an issue with Flask and requests to files in subdirectories of static.

A request for /static/test.css returns correctly, but a request for /static/test/test.css returns a 500 and throws this exception:

Traceback (most recent call last):
  File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/app.py", line 1991, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/app.py", line 1567, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/app.py", line 1642, in full_dispatch_request
    response = self.make_response(rv)
  File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/app.py", line 1731, in make_response
    raise ValueError('View function did not return a response')
ValueError: View function did not return a response

A bit of searching on that error returns mostly simple cases where someone forgot a return in a request handler, but nothing for when making direct requests for assets. It also does the same thing if trying to use url_for in a template to request the file from the subdirectory.

timwoj
  • 388
  • 4
  • 14
  • Just as a sanity check - does this `/static/test/test.css` file actually exist? – YellowShark Jan 02 '17 at 22:11
  • Yes and it has correct permissions. – timwoj Jan 02 '17 at 22:12
  • 2
    I think you might need to share some code. I just spun up a blank Flask project in Python 3.5.2, and created a `static/test/test.css` file, and it works fine. The contents of my app.py file are literally `from flask import Flask / Flask(__name__).run()`, nothing more than that. – YellowShark Jan 02 '17 at 22:20
  • Ah, you're onto it there. I forgot that I have a route that takes three parts as variables. It was falling under that and returning nothing (since I haven't implemented it yet). – timwoj Jan 02 '17 at 22:38
  • did you solve it? – metmirr Jan 02 '17 at 22:55
  • It's going to require me to special-case the `static` handler, but it's basically solved short of me writing that up. – timwoj Jan 02 '17 at 23:12

1 Answers1

0

This ended up being an error in my code. I have a route handler that takes three parts as arguments, and since that handler isn't implemented yet, it caused Flask to throw the exception above. I ended up implementing the solution from Does Flask support regular expressions in its URL routing? for that handler since I know the first part is always one of a few different values, and the static handler can run as normal.

Community
  • 1
  • 1
timwoj
  • 388
  • 4
  • 14