0

I just installed Passenger WSGI on my Dreamhost shared hosting to host a flask site. Their documentation is very poor and it took me entirely too long to figure out how to do things like touch tmp/restart.txt, but I finally got up and moving. To teach myself what to do, I am using Miguel Grinberg's Flask tutorial

I had gotten as far as lesson 2, using templates, when I started getting errors any time I used render_template(). This is a bit distressing because it was working for a little bit, then I changed routes.py, whereupon it quit working. Reverting routes.py didn't fix the problem. Unfortunately, Passenger on shared Dreamhost hosting has really crappy (read nonexistent) error logging so I don't know what the problem is beyond

I've looked at all the similar questions on here, and it seems that render_template errors are almost exclusively caused by not having a templates folder in the app directory. This isn't the case here. I tried doing the solution someone with a similar problem tried, and nothing.

Am I missing something really obvious? Here's the directory:

init.py

routes.py

templates/index.html

init.py:

from flask import Flask
app = Flask(__name__)
from public import routes

routes.py

from flask import render_template
from public import app

@app.route('/')
@app.route('/index')
def index():
    return render_template('index.html')

index.html (I can't imagine this being the problem, but just in case

<html>
  <head>
      {% if title %}
      <title>{{ title }} - Microblog</title>
      {% else %}
      <title>Microblog</title>
    </head>
    <body>
        <h1>Hello, World!</h1>
    </body>
</html>

I've tweaked and replaced nearly everything here. Everything works unless I try to use render_template. Is there somehow a problem with the location of the directory? It's exactly where it should be from everything I've read.

EDIT: Solved. I replaced HTML file with a fresh one and it worked. I guess render_template didn't like the indented and tags.

EDIT2: Not solved. It gives me this error seemingly at random for certain HTML files while not giving it for others. Because Dreamhost WSGI doesn't give me any error logging or ability to stack trace I'm completely in the dark here and plowing through Jinja2 questions for answers. There's no pattern, rhyme, or reason to files that give me errors versus ones that don't.

1 Answers1

0

Just to be sure this is not your problem. Have you checked your files permissions? All your hosted files must be readable (at least) by the group.

BTW you must have access to error logs via SSH. You may find the error.log file in $HOME/logs//https/error.log

If all your files have the necessary permissions and if you are really sure that nothing wrong is going on in the log, then you might be running into this problem, where Shared Servers on Dreamhost have some "random" troubles while serving files.

  • Dreamhost Passenger WSGI not logging to the regular system logs is a known issue. They offer a couple workarounds that other people claim breaks WSGI in new and different ways. If I can't figure this out any other way, I'll do my best to implement some kind of logging. As for permissions, both working and non-working HTML templates have permission set to 644. – Gay Deceiver Nov 29 '18 at 07:09
  • And I don't think the "random" explanation fits because I consistently have one working html file (index) and any other one I make not working. The next plan, I guess, is just to get the whole project working in PythonAnywhere and get a VPS from someone besides Dreamhost to actually implement a flask site. – Gay Deceiver Nov 29 '18 at 07:11