Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I would like to start writing Python web apps, first start simple like servlets in Java, then move to some web frameworks.
What server could I use to develop the apps? Is there a Tomcat version for Python? Is Apache with mod_python the way to go or something else?
I would like to know some options that may help with:
Python based local web development in my own laptop/ PC.
Creating production ready Python web applications.
Thank you!
PS: It is for Python 2.6.5, if that makes a difference
Tomcat is as far as I know only for Java.
You could use the Django-Framework. It has a integrated developmentserver and you can use Apache for a productive enviroment. But i recommend mod_wsgi instead of mod_python.
Here is an example for an wsgi application with apache and django:
# Apache Config
<VirtualHost *>
ServerName example.com
WSGIScriptAlias / /var/www/example/site.wsgi
ErrorLog /var/log/apache2/error.log
</VirtualHost>
# site.wsgi
import os
import sys
sys.path.append( rel(".") )
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I realize this question was posted a long time ago, but Zope would be an alternative
http://www.zope.org/
There is Django. I guess this could do the job.
Here is a good overview about this.
CherryPy http://www.cherrypy.org/
Google AppEngine appengine.google.com
Apache mod_py apache.org
lighthttp must also have python
support lighthttp.org
I would highly suggest learning Twisted. It makes webservers easy. It is an asynchronous framework the relies on the idea of callbacks. You set up a server. You define how the server responds to different inputs. And then as it receives data it will call the proper methods to handle each incoming request. the twisted.web http module is also very robust yet easy to step into. Great place to start.
See: the following
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have searched. Everything I can find is a huge file. It can't be that hard. C# has a SaveAs, PHP uses the $_FILES array. Python was all over the place. Cgi, httprequest, urllib, urllib2, httplib2, how to do it in Django, Pylons, Flask, etc. Java was complex as well.
All I want to know, please, is what is the most super-basic way to upload a file from a webpage.
Python 2.7 or Python 3 made no difference in my search.
Any help is appreciated.
EDIT: For clarification, I mean like any webpage that has the "Upload" button. Could be here, Craiglist, anything. All I really want to do is upload an image file and save it on the server.
EDIT: Part of the problem is there are so many libraries and everyone saying to use x.
EDIT: The server could be Apache or IIS.
"What is the simplest way to upload a file in Python from a web browser?"
I don't think there is a simple way, because this question doesn't make much sense. There are at least three ways to interpret this question :
If you want to upload a file with Python acting as a web-browser onto a remote server, one of the easiest ways is to use the requests library.
If you want to upload a file from a web browser, which Python is controlling, onto a remote server, then you could use the selenium library to drive a firefox browser.
If you want to upload a file with a web browser onto a remote server that is running Python, there is no "simple" way to do it. Python doesn't have the "it just runs" integration with apache like PHP does. While there are some open source projects for getting Python to work in Apache, most people opt to run their Python code either as it's own daemon or through some sort of WSGI server or proxy.
The simpler ways to handle #3-
The easiest way to do web stuff is web.py. Its very simple and limited.
If you're willing to do a bit more work, there are micro-frameworks like flask and bottle
There's another tier of minimalist frameworks, which contain pyramid, tornado, twisted, cherrypy and more. they tend to be very powerful, but don't make any decisions for you. Someone posted this link the other day comparing a few - http://codecondo.com/14-minimal-web-frameworks-for-python/
Finally you have full-fledged frameworks like django , turbogears, web2py, which make a lot of decisions for you.
Generally speaking, each framework deals with the GET/POST data from the request differently. While the cgi package is often wrapped, there's no real consensus on which library should be used to handle file uploads. A lot of frameworks seem to integrate webob to handle that stuff in a WSGI stack.
/updated/
Some simple ways to get python up and running:
most frameworks will offer a lightweight daemon for testing or low-load conditions. you can just run it as-is off the commandline , and it will bind to a high port (like 8080)
you can have Apache/IIS proxy requests to the higher port if you don't want to hit it directly
you can use something like gunicorn, uwsgi, eventlet, or probably 12+ other libraries to run the uwsgi environment.
personally, I do this
nginx on port 80
development - proxypass to the script's test-daemon, running on higher port ( for Pyramid/Pylons that is paster, for web.py it's just the commandline )
production - run via uwsgi
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
What is the simplest way of running a python script on the web?
I've been learning to use python to create really simple scripts that scrape the web and represent that data as HTML that can be cut-and-pasted into our CMS.
I'd like to share the technology with my colleagues without forcing them to install python on their machines and thought the web would be a great solution.
I've seen solutions ranging from Django to Flask, Tornado to Python On Wheels but I'm just getting overwhelmed by lots of server-speak.
Can anyone suggest a framework that makes it simple for newbies to get started and develop as I get more experience?
Secondary question: how easy - or not - would it be to have modules available to bolster the toolkit?
Have you considered trying Google App Engine. Some details here: https://developers.google.com/appengine/docs/python/
If you are only interested in scraping maybe scraperwiki is something for you. It allows you to build scrapers in python and it handles the storage.
And otherwise maybe this question has the answer.
You can set it up in apache with WSGI quite easily.. although not sure which OS you're runnin on the server.
For Ubuntu 12.04:
First, install Apache's module:
sudo aptitude install libapache2-mod-wsgi
Then, restart Apache:
sudo service apache2 restart
Then you can add a simple example program to test; install it in /usr/lib/cgi-bin/ then, just run from http://your-domain/cgi-bin/your-script.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
print "Content-Type: text/html" # needed to indicate that the content is HTML
print # blank line, end of headers, don't remove
print "Hello World!"
Hope that helps!
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have an app that I am working on that is currently hosted on google App engine. It is written in python and went pretty smoothly until my requirements changed and google app engine would not let me do what I needed to do. Currently I am trying to find a way to host my code (python) and be able to make and accept http:// requests, and be able to edit/add files in the same directory as the python scripts are located (I need to store lots of files, and the blobstore is just weird).
If this is not possible, I would be happy with being able to run python scripts "in browser" like when testing with google app engine, just on my local machine (windows 7 64 bit).
Any help is appreciated
Google's App Engine supports WSGI , not CGI.
You should be able to port your code to another stack that supports WSGI rather painlessly. There isn't much custom google-specific stuff on there.
Some popular frameworks that support WSGI include:
Pyramid
Tornado
CherryPy
bottle
flash
web.py
twisted
There are lots more
In terms of hosting:
Heroku can host Python WSGI apps
You can deploy on virtually any machine with uwsgi , apache's mod_wsgi, or countless other wsgi servers
Most frameworks have their own server for local development
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm trying to learn python/django, these are installed on my desktop computer and all the examples run fine. My question is: If a webhosting service supports python (2.4), does the webhosting service supports django by default?
Thanks guys.
You can use Google App Engine, which is free and includes Django.
Yes, but if they only support Python via CGI then your application will be very, very slow. Best is WSGI, then FastCGI, then mod_python.
Not necessarily.Many web hosting companies(shared) claim to offer django but this is a big lie.Case in point,a2hosting claims to have django but don't offer it;its disallowed.I tried to compile my own python and install django and found out that that path is also closed.
Django is memory intensive and will only work on vps and dedicated accounts.Web faction though is the only web host that wont lie to you.
Try Fornex VPS. https://fornex.com/vds/
I use it and like very much. Month payment starts from 5 euros. And you can install apache 2 + wsgi.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am leasing a dedicated web server.
I have a Python web-application.
Which configuration option (CGI, FCGI, mod_python, Passenger, etc) would result in Python being served the fastest on my web server and how do I set it up that way?
UPDATE:
Note, I'm not using a Python framework such as Django or Pylons.
I usually go the Apache + mod_wsgi route. It is pretty easy to set up.
To answer your question about speed, I pulled this from the provided link:
The mod_wsgi module is written in C code directly against the internal Apache and Python application programming interfaces. As such, for hosting WSGI applications in conjunction with Apache it has a lower memory overhead and performs better than existing WSGI adapters for mod_python or alternative FASTCGI/SCGI/CGI or proxy based solutions.
Don't get carried away with trying to work out what is the fastest web server. All you will do in doing that is waste your time. This is because the web server is nearly never the bottleneck if you set them up properly. The real bottleneck is your web application, database access etc.
As such, choose whatever web hosting system you think meets your general requirements and which you find easy to setup and manage. Using something you understand and which doesn't require lots of time devoted to it, means you can then focus your valuable time on making your application perform better, thus reducing the real bottleneck.
You may use pure python wsgi server (see benchmark) with microframework (like Bottle, Flask)
Use Apache + mod_python. It's usually the easiest way and it performs very well.
Edit: additionally, as it turns out, it is also considered a dead project. So that might factor into your decision. That said, mod_wsgi is the preferred alternative.
Tornado is an impressive high performance Python web server. It has it's own framework, but the speed/page load statistics are all the buzz right now.
Apache2 and WSGI is my other suggestion.
You don't usually just serve Python, you serve a specific web server or framework based on Python. eg. Zope, TurboGears, Django, Pylons, etc. Although they tend to be able to operate on different web server back-ends (and some provide an internal web server themselves), the best solution will depend on which one you use.