Forums

Deploying Flask app: 404 Not Found

I did everything with this doc: https://help.pythonanywhere.com/pages/Flask/ - but have ''404 Not Found' error: 109.252.79.79 - - [12/Nov/2019:11:34:00 +0000] "GET / HTTP/1.1" 404 232 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0" "109.252.79.79" response-time=0.002 - access.log. I had ImportError, but solved it. Now I can`t even realize where is the problem. But I have warning in wsgi.py file, that my app imoprted but unused - may be this is the reason? How can I solve it?

Thank you! ;-) :-)

You're getting a 404 because you are trying to access a path in your app and you have not defined a view for it in your Flask app.

You can ignore the "imported but unused" warning because the variable that is defined in your WSGI file is not used in your WSGI file, it's used by the system to find your web app.

Ok, but everything is working on my local machine with Flasks builtin development server, or when I using waitress on local machine.

Make sure that the variable that you're importing into the wsgi file is the application that properly defines your Flask application.

SOLVED!!!11

It <s>rocks</s> works! When working with Flask on pythonanywhere.com by this docs: https://flask.palletsprojects.com/en/1.1.x/tutorial/ - should write:

from site_name import create_app
application = create_app()

instead of

from app_file import app as application  # noqa

in hosting`s wsgi.py file, something like with Django.

Good luck everybody! ;-) :-) :-)

How did you write out site_name? I put the name from the url without the .com but I get a module not found errror.

Could you give some more details? What URL are you visiting, and that is the full error message?

I'm trying to get the second web app to work on a different domain. This one is cloned from the first. The first web app works nicely, but i've spent half a day trying to figure out why i'm getting 404 on the landing page for the 2nd web application.

Which web framework are you using? What code do you have to define a view for the root ("/") URL?

I'm using flask . Here's the code that defines a view for the root("/") URL

@home_blueprint.route('/')
@home_blueprint.route('/home')
def index():
        return redirect(url_for('home.index'))
    return render_template('home/index.html', title='Home')

I found the cause of 404 on landing page. It was the url_prefix that i added onto the home_blueprint!

...
    from app.home import home_blueprint
    app.register_blueprint(home_blueprint, url_prefix='/home')
...

Glad to hear that you made it work!