0

I'm using flask with passenger_wsgi and I can only get the default '/' route to work so my app.py looks like:

import os

from flask import Flask, request, render_template, redirect, url_for

project_root = os.path.dirname(os.path.realpath('__file__'))
template_path = os.path.join(project_root, 'app/templates')
static_path = os.path.join(project_root, 'app/static')

app = Flask(__name__, template_folder=template_path, static_folder=static_path)

@app.route('/')
def index():
    return 'Hello, World'

@app.route('/inplay')
def getInPlay():
    return 'This is a test'

if __name__ == '__main__':
    app.run()

and passenger_wsgi.py looks like

import os
import sys
import importlib.util

sys.path.insert(0, os.path.dirname(os.path.realpath('__file__')))
spec = importlib.util.spec_from_file_location("wsgi", "app.py")
wsgi = importlib.util.module_from_spec(spec)
spec.loader.exec_module(wsgi)

application = wsgi.app

If I got to my url with just api/ at the end it works and shows hello world, if I do api/inplay it 404s, not sure what I'm missing? thanks

garyk1968
  • 121
  • 3
  • 8
  • 1
    I had a similar problem where only the root URL would work and all other routes returned 404. Add the following to the top of your .htaccess file: `RewriteEngine on` `RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]` Got this info from: [https://stackoverflow.com/a/63971427/10122266] – taiff Nov 20 '20 at 07:19

2 Answers2

0

As I know, the /inplay route doesn't work this way. I am also trying to find out a working way. All the info online is just the simple hello world sample which is so useless. Phusion passenger should really publish some good samples so people can understand how easy this is to build a good python sample on Cpanel compared to using gunicorn nginx etc(which might be not possible on limited access web hosting server). Please do share if you find out how to route other path or even use it on templates,static structure.

poc
  • 11
  • 3
  • 1
    I had a similar problem where only the root URL would work and all other routes returned 404. Add the following to the top of your .htaccess file: `RewriteEngine on` `RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]`. Got this info from: [https://stackoverflow.com/a/63971427/10122266]. – taiff Nov 22 '20 at 03:22
0

Ok, this works - RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]

The trick is to figure out which .htaccess to update.

Go to the root public_html of your site. You will now find a new directory in the name of your app. Go to that sub directory and edit the .htaccess file in that location. This file will already have rules about the python config. Just add the following at the bottom -

RewriteEngine On
RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]

Save the updates to the .htaccess and thats it.

d5t
  • 51
  • 3
  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](/help/whats-reputation) you will be able to [comment on any post](/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). – 4b0 Feb 08 '21 at 03:52