I've tried a few paths for the static files location configuration and the WSGI file containing folder in my config, but I cannot seem to get it right somehow. I'll describe the structure of my flask project below.
I have a file named app.py
in markdown_blog/app/app.py
. In this file I declared my routes and there is the magical line app = Flask(__name__)
.
In my wsgi file I have:
import sys
wsgi_path = '/home/Zelphir/markdown_blog/app/'
if wsgi_path not in sys.path:
sys.path.append(wsgi_path)
from app import app as application
and only comments besides that.
My static files are inside my app under markdown_blog/app/static/
. There are subdirectories there, for example markdown_blog/app/static/css
or markdown_blog/app/static/js
.
I pointed the static files path in the web config to: /home/Zelphir/markdown_blog/app/static/
The site itself runs, but as soon as I try to read any files from /static/markdown/chinese/blog/
inside my app.py
, which contains markdown files, which contain blog posts, I get the following errors in the error log:
2016-05-15 15:28:17,891 :Exception on /chinese/blog [GET]
Traceback (most recent call last):
File "/home/Zelphir/.virtualenvs/markdown_blog/lib/python3.5/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/Zelphir/.virtualenvs/markdown_blog/lib/python3.5/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/Zelphir/.virtualenvs/markdown_blog/lib/python3.5/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/Zelphir/.virtualenvs/markdown_blog/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/Zelphir/.virtualenvs/markdown_blog/lib/python3.5/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/Zelphir/.virtualenvs/markdown_blog/lib/python3.5/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/Zelphir/markdown_blog/app/app.py", line 25, in mandarin_blog
complete_html_content = post_renderer.render_posts_from(dev_prefix + '/static/markdown/chinese/blog/')
File "/home/Zelphir/markdown_blog/app/PostRenderer.py", line 12, in render_posts_from
file_list = get_all_files_in_folder(directory_path, file_extensions=markdown_extensions)
File "/home/Zelphir/markdown_blog/app/helpers/filesystem_helper.py", line 13, in get_all_files_in_folder
for item in os.listdir(file_path):
FileNotFoundError: [Errno 2] No such file or directory: '/static/markdown/chinese/blog/'
So I get the impression that the mapping for static files does not work inside my app, maybe only works when a path to a static file is in the rendered HTML and then the browser asks for that file using the static link. However, I need to access those files before that in order to render the markdown files to blog post HTML. Also I need later access to CSS and JS files from the rendered HTML in the browser of the visitor.
How do I configure this?
My app's code can be seen on [Github].(https://github.com/ZelphirKaltstahl/MarkdownBlog)