5

I'm new to flask. I want to deploy my flask application on prod, so for that I want to use Twisted web server (on windows). Below is my proj structure and I'm using Blueprints: enter image description here

my run.py file is as below:

#!/usr/bin/env python

from ProjName import app

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

command I'm trying is :

twistd web --wsgi run.app

In top most init.py I'm just doing :

app = Flask(__name__)

And rest code is related to registering blueprints.

What changes do I need to make in my files so as to run on twisted web? Or do I need to completely restructure my code?

PS: I know my question may not be clear. I've referred some links but it is just confusing me. Appreciate your help!

gB08
  • 182
  • 2
  • 10

1 Answers1

5

You haven't put the root of your source tree into Python's import path so the module name "run" can't be resolved. Fix it by setting PYTHONPATH (for example):

export PYTHONPATH=${PYTHONPATH}:${PWD}
twistd web --wsgi run.app
Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122
  • I've set this PYTHONPATH. But still getting same error. – gB08 Oct 17 '17 at 06:01
  • You can run `python -v $(type -p twistd) web --wsgi run.app` to get import search path debug information which may help you narrow the problem down further. – Jean-Paul Calderone Oct 17 '17 at 15:11
  • 1
    this is also valid and can be useful on Windows where one can write something like `set PYTHONPATH=F:\Appl\myapp\flask;` –  Feb 25 '21 at 09:43