[Flask] Deploying on httpd and mod_wsgi

Corey Boyle coreybrett at gmail.com
Thu Sep 22 17:21:16 EDT 2016


Maybe something along the lines of...

import sys

import os

INTERP = os.path.expanduser("~/env/[appname]/bin/python")

if sys.executable != INTERP:

    os.execl(INTERP, INTERP, *sys.argv)

sys.path.append(os.getcwd())

from [appname] import app as application

On Sep 22, 2016 4:56 PM, "Craig Amundsen" <amundsen.craig at gene.com> wrote:

> Thanks for all the suggestions. In order to let the internet remember this
> for me, here's what worked. In the mod_wsgi docs there's a throwaway line
> about if you don't have a factory method put "from app import app as
> application".
>
> The example app you build in the Grinberg book does have you implement a
> factory method. This .wsgi file worked for me:
>
> ================================
> import os
> import sys
>
> sys.path.insert(0, "/var/www/CraigsApplication")
>
> from app import create_app
> application = create_app(os.getenv('FLASK_CONFIG') or 'default')
> ================================
>
> Thanks for the prompting about using a virtualenv. I'm not using one and
> that's my next stumbling block. I don't have root on this machine and I
> didn't want to use the system python, so I built my own more current
> python. In my .bashrc I have ensured that the path to my custom python is
> before /usr/bin so when I log in I get the correct python. Apache/mod_wsgi,
> though, are using /usr/bin/python which doesn't have any of the
> Flask-required libraries.
>
> Can anyone tell me how I force it to use a non-default python?
>
> Thanks,
> - Craig
>
> On Thu, Sep 22, 2016 at 1:20 PM, Alex Alex <alex-alex-90 at wp.pl> wrote:
>
>> Hi,
>> I'm not an expert on mod_wsgi and Apache. In fact I've used it many years
>> ago for the last time.
>>
>> Are you sure your imports are fine? The error says that you are missing
>> LCD module - probably it is installed on your laptop but not the on the
>> server. Without seeing your requirements.txt and flask app imports I guess
>> it will be hard to say something more.
>>
>> As for Apache unless you have some special requirements you may want to
>> check out gunicorn - it works nicely with flask applications and is python
>> based. That is how I run test instances on Heroku actually.
>> Cheers
>> Alex
>>
>>
>>
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160922/646d2be2/attachment-0001.html>


More information about the Flask mailing list