Forums

App imported but not used

Hey,

it's my first time deploying a Flask app. I went through tutorial and it seems like I've sucessfully cloned my GH repo, established a virtualenv (although I'm not sure in what location should it be created and if if does even matter?), but when it comes to configuration of WGSI file, it gives a warning that app variable has been imported but not used. My app runs, but instead of actual content, it returns a default "Hello from Flask!" message. Any thoughts?

The warning that the application variable is imported but not used is good/normal. That's because we will import your wsgi file and access the application variable to run your website!

Have you reloaded your webapp?

Yep, I have.

Is it possible that I didnt link my WSGI to the code corectly? As it seems not to recognize it at all.

The app is structured as a package and the actual structure is like this: https://github.com/JakNowy/FlaskWebsite. Source code path is set to "/home/Kobe/FlaskWebsite/ ".

WGSI file:

import sys
project_home = u'/home/Kobe/FlaskWebsite/'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

from FlaskWebsite import app as application  # noqa

EDIT: The error logs say that there's no module named FlaskWebsite.py. Did I mess something with WSGI?

It looks like you've fixed the problem now -- your site is up and running, at least. Did you work out what the issue was?

Looking at the error log, the last message was this:

2018-08-02 10:10:47,378: Error running WSGI application
2018-08-02 10:10:47,379: ModuleNotFoundError: No module named 'FlaskWebsite.py'
2018-08-02 10:10:47,379:   File "/var/www/kobe_pythonanywhere_com_wsgi.py", line 16, in <module>
2018-08-02 10:10:47,379:     from FlaskWebsite.py import app as application  # noqa
2018-08-02 10:10:47,379: ***************************************************
2018-08-02 10:10:47,380: If you're seeing an import error and don't know why,
2018-08-02 10:10:47,380: we have a dedicated help page to help you debug: 
2018-08-02 10:10:47,380: https://help.pythonanywhere.com/pages/DebuggingImportError/
2018-08-02 10:10:47,380: ***************************************************

The problem is this line in your WSGI file:

 from FlaskWebsite.py import app as application  # noqa

-- you shouldn't include the .py file extension when importing a Python module. It should just be this:

 from FlaskWebsite import app as application  # noqa

Yes, it's working but still returning default "Hello from flask" template rather than my actual application.

I created a dummy app in the same folder and it worked properly (displayed the dummy template). When I switched back to mine, it returned the default one once again. The only difference is that I'm importing the app from a package (that includes init.py and the "app" variable is instantiated there) file instead of actual myapp.py module.

To be even more clear:

from FlaskWebsite.FlaskWebsite import app as application

^ returns a default "Hello from flask"

from FlaskWebsite.dummy import app as application

^ returns the dummy template

Does it mean that I the app cannot be structured as a package? The code itself runs smoothly on local machine. Please help me guys :|

That sounds like whatever you have in the FlaskWebsite.FlaskWebsite is set to return "Hello from flask". Look at the files in that directory to veerify that.

Shame on me, I forgot it overrides that "app-file" if it exists. Thank you guys!

Glad you worked it out :-)

[edited by admin: code formatting]

import sys
path ='/home/ogbajestephen2020/Portfolio'
if path not in sys.path:
    sys.path.append(path)

from server import app as application

guys please help

What is the problem you're dealing with?

2020-11-04 14:55:16,452: Error running WSGI application 2020-11-04 14:55:16,455: ModuleNotFoundError: No module named 'flask' 2020-11-04 14:55:16,456: File "/var/www/twin0007_pythonanywhere_com_wsgi.py", line 16, in <module> 2020-11-04 14:55:16,456: from app import app as application # noqa 2020-11-04 14:55:16,456: 2020-11-04 14:55:16,456: File "/home/twin0007/mysite/app.py", line 1, in <module> 2020-11-04 14:55:16,456: from flask import Flask,render_template,request 2020-11-04 14:55:16,456: ********* 2020-11-04 14:55:16,457: If you're seeing an import error and don't know why, 2020-11-04 14:55:16,457: we have a dedicated help page to help you debug: 2020-11-04 14:55:16,457: https://help.pythonanywhere.com/pages/DebuggingImportError/

guys please help

Have you tried https://help.pythonanywhere.com/pages/DebuggingImportError/?

Has anyone resolved this issue? seems we all have the same problem...

Flask_app module not found...

Have you tried https://help.pythonanywhere.com/pages/DebuggingImportError/?

Yes i read through it many times.

WSGI configuration file:

import sys

path = '/home/Quarky33/Portfolio'
if path not in sys.path:
    sys.path.append(path)

from server import app as application

I'm guessing i don't need __init__.py files because i'm already searching my path directory for my python file server.py which is inside.

From this file i am calling app = Flask(__name__).

But keep getting the error that the module 'server' can not be found.

When running python -i /var/www/www_my_domain_com_wsgi.py in with BASH (in my virtualenv with python 3.9 as default), nothing happens. ..

[edit by admin: formatting]

Are you sure that you are looking at the most recent error? The most recent errors are at the bottom of the error log.

Actually, every time i refresh my site link, try opening the page unsuccessfully and then go back to click on the error log, i am getting the previous errors from about 2 days ago. The error log does'nt seem to be refreshing? But i'm pretty sure it's just the one error repeated about 5 times one after the other.

What link are you "refreshing" and what do you see under that link?

this link

Quarky33.pythonanywhere.com

and then i go to the error log and the last entries i have are still from the 25/09. (sorry for late reply, i i didn't turn on notifications)

How does your routing look like? Do you have a view for the root url of your web app?

Sorry you'll have to explain what that is and where i can find it?..

OK, I asked about the routing because when I tried to visit your web app, I got 404 error, which means that your web app doesn't serve the root path "/" (effectively that is what you get when you go to Quarky33.pythonanywhere.com/). It's possible that error log wouldn't be updated in such a case. You should see 404 for "/" in the access log though. If you've got other views defined, you may try hitting them and see if the web app works as you intended or if some errors appear in the error log.