Flask deployment using twistd - python

In the flask doco the following description is shown of deploying a flask app under twistd.
twistd web --wsgi myproject.app
I have a foo.py which looks like this
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
So I expected to be able to run that under twistd like this
twistd web --wsgi foo.app
but twistd doesn't like that (just spits out the help text).
What am I doing wrong ?
BTW in case it matters I'm running this in a virtualenv (in which I have installed both flask and twisted) and the current directory when I issue the twistd command contains foo.py .
EDIT: The version of twistd I am using is 18.7.0
I had failed to notice (until prompted to by Peter Gibson's comment ) that after the help text appears the message "No such WSGI application: 'foo.app'" appears.

You need to add the current directory to the PYTHONPATH environment variable. Try
PYTHONPATH=. twistd web --wsgi foo.app
Or on Windows (untested)
set PYTHONPATH=.
twistd web --wsgi foo.app

Related

Trying to create a simple flask

I am trying to make a simple flask app using putty but it is not working
here is my hello.py file:
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello():
return 'Hello, World'
command I am running in putty (when in the file directory of hello.py)
pip install flask
python -c "import flask; print(flask.version)"
Output:1.1.2
export FLASK_APP=hello
export FLASK_ENV=development
flask run
when I go to the ip address: http://127.0.0.1:5000/
I get this
enter image description here
also here is the link of the instruction I am following/did:
https://www.digitalocean.com/community/tutorials/how-to-make-a-web-application-using-flask-in-python-3
if someone could let me know how to make it work would be great!
thank you!
I used my terminal on my window machine instead of putty which is a remote machine
Check your wlan0 inet adress by typing ifconfig in bash and use it, also try to add the following code in your flask app:
if __name__ == '__main__':
app.run(debug=True, port=5000, host='wlan0 IP Add')
Run the application by typing >>sudo python3 hello.py
Did this work?

flask.cli.NoAppException: The file/path provided (new_app.py) does not appear to exist

I keep getting this error flask.cli.NoAppException: The file/path provided (new_app.py) does not appear to exist. Please verify the path is correct. If app is not on PYTHONPATH, ensure the extension is .py it goes away after I restart the Flask server.
I am running flask run in the correct directory where my app is. This just started happening after working for 2 weeks. I've read that it could be due to an import error, but I am not finding any modules that are not installed on my virutalenv.
from flask import Flask
app = Flask(__name__)
app.debug=True
Most likely you haven't set the FLASK_APP environment variable.
To run the application you can either use the flask command or
python’s -m switch with Flask. Before you can do that you need to tell
your terminal the application to work with by exporting the FLASK_APP
environment variable:
$ export FLASK_APP=hello.py
$ flask run * Running on http://127.0.0.1:5000/
If you are on Windows you need to use set
instead of export.
Alternatively you can use python -m flask:
$ export FLASK_APP=hello.py
$ python -m flask run * Running on http://127.0.0.1:5000/
EDIT
If you have FLASK_APP set then try adding this to new_app.py
app.run(debug=True, port=8800)
Or if you're on Windows:
if __name__ == '__main__':
app.run(debug=True, port=8800)
And then just execute the app with python new_app.py.

unable to deploy the python pyramid web apps to heroku

This is the Error logs I find in the heroku when deploying the python pyramid application. I have followed the each and every steps the python pyramid documentation has. Where have I exactly missed not able to figure out.
I doubt if my way of creating run file is incorrect. I have created a run.py
file and added the following code into it.
#!/bin/bash
set -e
python setup.py develop
python runapp.py
You cannot host a web app like that. You need a proper server, for example gunicorn - see the Pyramid docs on how to run with gunicorn, that is what needs to go in your Procfile. You don't need a run.py.
Try this:
Profile
web: ./run
run
#!/bin/bash
set -e
python setup.py develop
python runapp.py
runapp.py
#Heroku Startup
import os
from paste.deploy import loadapp
from waitress import serve
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app = loadapp('config:production.ini', relative_to='.')
serve(app, host='0.0.0.0', port=port)
requirements.txt
pyramid
pyramid_chameleon
pyramid_debugtoolbar
waitress
<add other dependencies here>
runtime.txt
python-3.3.0 #or whatever version you are running. Take this out

Flask app is not start over twisted 16.4.X as wsgi

I have simple Flask app test.py:
from flask import Flask
app = Flask(__name__)
#app.route('/')
def test():
return 'Hello world!'
if __name__ == '__main__':
app.run()
Run over twisted 16.3.0 work fine:
twistd -n web --port 5000 --wsgi test.app
After upgrade twisted to 16.4.0 i have got error on start:
No such WSGI application: 'test.app'
What is mean?
Your are likely picking up the test module which is part of the Python standard library. Rename your code file (module) to something else. You also may need to set PYTHONPATH so it looks in the directory where code module is.

Flask not working in Virtualenv setup

SetUp
VirtualBox | Ubuntu Server 12.04.2
(flaskve)vks#UbSrVb:~/flaskve$ python --version
Python 2.7.3
ifconfig
192.168.1.100 (the bridge interface on which i interact with VirtualBox)
code I am trying to run.
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run(host='192.168.1.100', port=8080, debug=True)
When I do
(flaskve)vks#UbSrVb:~/flaskve$ python start.py
(flaskve)vks#UbSrVb:~/flaskve$
It does not run or do anything, it just returns back to command prompt. Although I am running in debug=True mode.
I then made a new VirtualEnv and install bottle in that. When I tried to run helloworld it shows the same behaviour.
However I then started the python shell on the same virtualenv, imported bottle modules and ran
>>> from bottle import route, run
>>> run(host='192.168.1.100', port=8081, debug=True)
Bottle v0.11.6 server starting up (using WSGIRefServer())...
Listening on http://192.168.1.100:8081/
Hit Ctrl-C to quit.
What could be problem here ?
Even debug does not show anything.
Following link is the output of python -v start.py
http://paste.ubuntu.com/5713138/
The first example uses Flask, not bottle. Maybe you are confusing your code snippets here? :)

Categories

Resources