WebFaction
Community site: login faq

Hi, so I'm still having trouble setting up flask in webfaction.

I have a flask folder, where I have my htdocs and apache2 folder. I've installed flask.

My structure:

/flask/
 - /htdocs/
 -   - index.py
 -   - /app/
 -   -   - app.py
 -   -   - /users/
 -   -   -   - views.py

But I'm getting this error:

[Sun Nov 18 05:21:48 2012] [error] [client 127.0.0.1] mod_wsgi (pid=2042): Target WSGI script '/home/<myusername>/webapps/flask/htdocs/index.py' cannot be loaded as Python module.
[Sun Nov 18 05:21:48 2012] [error] [client 127.0.0.1] mod_wsgi (pid=2042): Exception occurred processing WSGI script '/home/<myusername>/webapps/flask/htdocs/index.py'.
[Sun Nov 18 05:21:48 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Nov 18 05:21:48 2012] [error] [client 127.0.0.1]   File "/home/<myusername>/webapps/flask/htdocs/index.py", line 7, in <module>
[Sun Nov 18 05:21:48 2012] [error] [client 127.0.0.1]     from app import app as application
[Sun Nov 18 05:21:48 2012] [error] [client 127.0.0.1]   File "/home/<myusername>/webapps/flask/htdocs/app/__init__.py", line 9, in <module>
[Sun Nov 18 05:21:48 2012] [error] [client 127.0.0.1]     from app import app
[Sun Nov 18 05:21:48 2012] [error] [client 127.0.0.1]   File "/home/<myusername>/webapps/flask/htdocs/app/app.py", line 14, in <module>
[Sun Nov 18 05:21:48 2012] [error] [client 127.0.0.1]     from app.users.views import mod as usersModule
[Sun Nov 18 05:21:48 2012] [error] [client 127.0.0.1] ImportError: No module named users.views

My app.py looks like this:

app = Flask(__name__)
app.config.from_object('config')

@app.errorhandler(404)
def not_found(error):
    return render_template('404.html'), 404

from users.views import mod as usersModule
db.init_app(app)
app.register_blueprint(usersModule)

And it fails on the from app.users.views line.

I have a users folder under my "app" folder, and it has a views.py.

Here's part of my httpd.conf, I am trying to access my url: http://x.webfaction.com/<subfolder>/

WSGIPythonPath /home/<username>/webapps/<subfolder>/htdocs:/home/<username>/webapps/<subfolder>/htdocs/users:/home/<username>/webapps/<subfolder>/htdocs/static:/home/<username>/webapps/<subfolder>/htdocs/templates:/home/<username>/lib/python2.7:/home/<username>/webapps/<subfolder>/lib/python2.7/site-packages
WSGIScriptAlias / /home/<username>/webapps/<subfolder>/htdocs/index.py

<Directory /home/<username>/webapps/<subfolder>/htdocs>
    AddHandler wsgi-script .py
    RewriteEngine on
    RewriteBase /<subfolder>/
    WSGIScriptReloading On
</Directory>

But for some reason using app.users.views doesn't seem to call my script. All my code works fine in localhost. Please help?

Perhaps my mistake is naming the folder "flask" which might conflict with "flask" keyword in python?

asked 17 Nov '12, 23:04

execute
726
accept rate: 0%

edited 22 Nov '12, 18:03


You will want to name it something other than 'flask' since, as you point out, that will cause conflicts with the module named flask. You will also want to verify the directories have a file named,

__init__.py

To make them modules. If you still have trouble submit a support ticket so we can take a closer look.

permanent link

answered 18 Nov '12, 00:21

johns ♦♦
5.3k212
accept rate: 23%

I'm going to assume you meant "myuser.webfactional.com/id".

A 502 error means that your app cannot be reached via its assigned port (eg, it's not running, or perhaps it is running but listening on the wrong port). Check the httpd.conf for your 'infernodevelopment' app to ensure that the Listen directive is set to use the port assigned to that app via our control panel, and that your app is actually running.

Hope that helps!

(19 Nov '12, 12:29) seanf

Oh yea the listen port being fixed definitely helped and fixed the 502 issue. I didn't notice that.

However, I'm still getting a "no module named "users.views". So app.py cannot import views.py from users folder. When I type x.webfactional.com/id/.

It says also "File does not exist: /home/<user>/webapps/id/htdocs/users" when I type x.webfactional.com/id/users/login.

Except it should be looking for /htdocs/app/users" not "htdocs/users"

(20 Nov '12, 00:51) execute

This seems like it might be a python path issue. Specifically, you're trying to load "users.views", and the 'users' directory is inside of "/home/<user>/webapps/flask/htdocs/app", so that's a directory you need on your WSGIPythonPath.

Looking at the WSGIPythonPath provided, I see ""/home/<user>/webapps/flask/htdocs/" on the path, but I don't see "/home/<user>/webapps/flask/htdocs/app" on the path. You probably need both.

(20 Nov '12, 02:08) ryans ♦♦

Yep I did that, but still didn't work. I also removed the "app" folder, and put everything in /htdocs, and just kept the users folder, but it still cannot find "/htdocs/users" even though it is added to sys.path (inside index.py and app.py), and even though I added it to httpd.conf and restarted the server. For some reason it now says File Not Found for users/login or users/account, like as if blueprint isn't working.

(20 Nov '12, 20:49) execute

Did you submit a support ticket? I just answered an almost identical question for a user and the problem had to do with the fact 'app.py' was calling a module in 'users/views.py' but users/views.py was also causing app.py, thus causing a circular import problem.

(20 Nov '12, 22:45) johns ♦♦

Yes I did. Yeah it was. The only problem now is that for some reason /id/user/login redirects to /user/login removing the id folder, and File Cannot be found for "user/login", so the pathing / url is messed up when you use blueprint. Has anyone gotten blueprints working in webfaction?

(21 Nov '12, 12:09) execute

I think this thread on the Flask mailing list might have the answer: Running behind proxy with URL prefix other than /

Hope that helps!

(21 Nov '12, 13:54) seanf

I don't understand how to do that. I've already added WSGI middleware in _init_.py, but that's all I can do. I don't think this extra proxy/header stuff needs to be done.

Ok so I updated my httpd.conf and changed the RewriteBase back to /id/ apparently it was at '/'. And I got the login page to work. But other pages are not so lucky.

(22 Nov '12, 16:06) execute

So when you type /id/users/login/ it works. when you type /id/users/login (no trailing slash), it redirects to /users/login (removing the 'id' folder). I wonder why this is happening. There must be some setting somewhere to prevent it from redirecting based on no '/' at the end.

(22 Nov '12, 16:54) execute

Ok so when you add the @bp.route('/user/login') as well as /user/login/, then it works. A bit strange, I wonder if there is an easy way to type this out.

(22 Nov '12, 18:00) execute
showing 5 of 10 show 5 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×62
×44
×27
×19
×2

question asked: 17 Nov '12, 23:04

question was seen: 5,075 times

last updated: 22 Nov '12, 18:03

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM