If you're just wanting to install a new Python 3.4 Flask application, you can install it in its own virtual environment using something like:
To serve it, create a Custom Application (Listening on Port) and run the flask application on the assigned port within the virtual environment (a watchdog script makes it easy to do this reliably). Since it's a virtual environment, it's also extremely easy to deploy an app that you've developed locally. answered 06 Sep '14, 08:25 ryans ♦♦ |
Step 1 First, install a " Then, mount it to a website record. I'll use " Step 2 Next, open an SSH session. Enter the following commands to deploy flask.
Hope that helps! Acknowledgements: I incorporated pieces of the Flask WSGI guide, Flask WebFaction Snippet, and Flask Hello World example to create this guide.
permanent link
This answer is marked "community wiki".
answered 12 Mar '13, 22:16 ryans ♦♦ Awesome reference and resource Ryan. Thank you for posting what you learned. Any guidance on how I could modify/update your script to allow the application to use virtualenvwrapper? Chris K.
(15 Aug '13, 00:54)
chrislkeller
Hi Chris, First of all, let me say that the use of virtualenv is not recommended and it is usually much better to just configure things as described in the above post. But if you really want to add extra layers of abstraction and complexity into your app, here is how you can do it.
(15 Aug '13, 11:25)
likebike
Well written Ryans. I noticed you put everything into the 'init.py' file (markup kills the underscores, sorry) instead of the index.py that you created in step 2. One can easily put the code in index.py and have the page still load if you modify the wsgi file to: from $APPNAME.index import app as application This allows the 'init.py' to remain empty or have additional package information in it, instead of code. This also helps avoiding confusion or conflicts when further code is developed.
(13 Sep '13, 09:36)
pbulsink
Thanks SO MUCH Ryan. It worked like a charm. Love and peace, Joe
(06 Mar '15, 00:57)
jdor
Thanks for the effort releasing this - worked great!
(01 Aug '16, 20:48)
Baron
|
I've created a project that automates creating a local Flask development environment, a production Flask environment on Webfaction, and hooks the two together. At the end of the automation you'll have a local Git repo with a Python virtualenv with Flask installed, a deployed minimal working Flask app, and a Fabric deployment script. Check it out on GitHub answered 26 Feb '16, 04:04 edgewood |
This is the best resource I've found: Deploying a Flask Project on Webfaction All it's missing is a middleware snippet if you intend to serve from somewhere other than "/". Luckily, the author of Flask has provided such a snippet This might not differ tremendously from @ryans solution, but most of the time I'm trying to push an existing project onto WF, so creating it on the fly in the command line like that isn't practical nor is it consistent with how I've ever done any development. Seeing things broken down in steps and by file, like in the post that I've linked to, is much more intuitive to me. answered 03 Sep '14, 19:34 mattparrilla |
Hi there, any chance someone can add clear step-by-step instructions on how to set the static folder on Flask to be served by nginx? I cannot find any simple, straightforward solution. Edit: After searching around, I found this answer which allowed me to find the solution:
Done! answered 02 Feb '15, 18:27 joaoventura |
Where are the logs in such an application? I can't seem to find anything for troubleshooting purposes. answered 10 Aug '15, 15:10 walton Your app's access and error logs can be found in
(10 Aug '15, 15:15)
seanf
|
I've just written a small step-by-step tutorial on my personal blog on how to setup Flask on webfaction. You can find it here: http://joaoventura.net/blog/2016/flask-webfaction/ The idea is simple, and I'll write a condensed version here, should my blog disappear someday:
The local directory structure should look like:
Use vim to open the apache configuration file (myproject/apache2/conf/httpd.conf) and do the following changes:Load the alias module:
Modify the Directory section:
Add the following lines at the end of the file so that your url's don't have "/index.py/" as prefix and that the static folder is served by apache:
Finally open htdocs/index.py with vim and do the following changes:
Save files, make sure the server restarts (./apache2/bin/restart) and everything should work..
permanent link
This answer is marked "community wiki".
answered 05 May '16, 21:03 joaoventura Thanks for sharing! However, I'll recommend a couple of changes:
(05 May '16, 21:09)
seanf
Hi Sean, you're right! In my blog post I talk a little bit about the WSGIPythonPath and the WSGIDaemonProcess, although I still prefer to have python "things" in python files. Regarding your other suggestion about creating a static-only app to serve the static content, it is definitely the recommend way..
(05 May '16, 23:13)
joaoventura
|
Hello, I followed joaoventura tutorial and was able to deploy my flask app, nonetheless it needed a few tweaks:
now the app is running except I got index.py as suffix in all my urls, even if in my httpd.conf I have the WSGIScriptAlias declaration: "WSGIScriptAlias / /home/<username>/webapps/<myapp>/htdocs/index.py" Obviously that <username> and <myapp> are just generic references.. Can anyone help me solving this issue? Why WSGIScriptAlias isn't working??? Thx, All the best, ktk answered 10 Nov '16, 11:25 ktk Here is a complete
Be sure to change the Listen port number, USERNAME, APPNAME, and ENV_DIR to the correct values for your app. Also, there's no need to modify Hope that helps!
(11 Nov '16, 01:50)
seanf
Hello seanf, Sorry for this delayed answer... 1st) Thx for the config file!!! 2nd) What do you mean by the sys.path in the index.py file??? Then my index.py file just looks like: from main import app as application Could it be? If yes, something is wrong because I keep having a gateway timeout error!!! Do you have an idea??? All the best, MFC
(01 Dec '16, 15:28)
ktk
Also, now my root domain doesnt resolve: it redirects to index.py which returns a 404! all other urls are working except the root url... Any ideas?? All the best
(01 Dec '16, 15:43)
ktk
What I mean is that you don't need to set The timeout is probably due to a Python C extension module, some of which are known to cause timeouts when used under mod_wsgi. There's a clear explanation of the problem (direct from the author of mod_wsgi) available at http://serverfault.com/a/514251/109598 The solution is simple - add the following to the app's httpd.conf:
Be sure to restart the app's Apache after making that change.
We'd have to take a look at your actual code to assist with that. Please open a support ticket for further assistance.
(01 Dec '16, 19:47)
seanf
|
Hello seanf! Again, thx for your help I trully appreciate it! I checked the logs and in fact the problem was way simpler: 1st problem: an error in my config was pointing the server name wrongly; 2nd problem: also in my config file was preventing the images to load, the app kept trying till it got a timeout I've set; After correcting these issues theh app restarted smoothly.. Just for info: Yes, my index.py now only have the line that initiates the app.. Again seanf, thx for your help!!! answered 02 Dec '16, 07:33 ktk |