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 need to create a simple website, the server is gonna running on Amazon EC2 web service. But I haven't done web development before. It seems like I need to learn a lot of stuff, javascript, html, css, web framework, WSGI, apache web server, etc. And I am confused by some stuff that seems much the same.
So first question, Can anyone tell me what exactly do I need to set the website up. Is a web framework the only thing I need on the server side?
2th question, I am gonna use python on server side, there are really a bunch of web frameworks for python. What's the difference between apache http server and the built-in wsgi or http web servers in those web frameworks.
3th question, Is WSGI the best choice? Most web frameworks support WSGI, does it mean WSGI is built in the web frameworks? Or I need to include mod_wsgi or something alike.
Also, according to this benchmark of python WSGI servers, gevent and mod_wsgi show great performance with low memory footprint. They don't claim themselves as web frameworks, what's the difference between them and the web frameworks like cherrypy, web2py.
Thanks
Depends on your website - if you only need static content, you can use static site generators (Blogofile, Hyde to name a few written in Python) or, if your website serves dynamic content, you should use some kind of framework (Flask, Django, etc). With static site generators all you need on the server is the webserver that serves your content, but with dynamic sites you might need extra libraries for various things like database support, caching, etc.
The built-in webservers are usually meant for local development and are generally not suitable for production use. For latter use the specific apps like mod_wsgi (for Apache) or uwsgi (for Nginx) instead. But try to avoid mod_python!
WSGI stands for Web Server Gateway Interface and is a standard protocol used between web server and web application (or framework). WSGI seems to be currently the only standard choice, so go with it.
Also, according to this benchmark of python WSGI servers, gevent and
mod_wsgi show great performance with low memory footprint. They don't
claim themselves as web frameworks, what's the difference between them
and the web frameworks like cherrypy, web2py.
As said before, WSGI is just a way that web server talks with web application. CherryPy and web2py deal with templating, request and session handling and output this information via WSGI to the web server.
And if you worry about the speed, then don't worry about it too much.. :)
WSGI is an interface. It requires a container (e.g. mod_wsgi), an application (e.g. Django), and optional middleware. Applications can be built directly against WSGI, or they can be built on top of frameworks such as Django that handle the WSGI bit for you.
Don't use the built-in web server in the frameworks. They aren't usually designed for performance, and they usually don't integrate well with the non-WSGI parts of your server.
You will need the web server, Apache is one popular choice. You will probably also need to install Database, MySQL is free, easy and popular.
The most popular (and best in my opinion) python framework is Django.
Many run Django with apache using mod_wsgi. Frameworks usually only provide development server that is not suitable to be a real server.
The WSGI servers probably only offer request handling and entry points for writing the code, but frameworks offer much more (user handling, admin interface, ORM, templating, etc...).
This isn't exactly a programming question, since you're really just asking how to get started with web development, and there is no clear answer to this.
I can warmly recommend getting started with Django, simply because it is very well documented and has great tutorials. It also uses Python which means it is easier to understand other people's code.
Regardless of whether you choose Django or something else, just choose a web application development tutorial and run through it. Google for one (for Django you can ask on the very helpful #django IRC channel). That should give you a good basis with at least one working example which you understand, as well as a clear picture of what the different pieces of a running web application are and how they work together.
Afterwards you can branch off and learn many various relevant skills and technologies, preferably driven by your needs as you develop an actual web application of your own (even if just for learning purposes at first).
Good luck!
Related
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 9 years ago.
Improve this question
now bear with me please. I'll explain from the beginning but very briefly.
8 months ago, I worked in a web project with python, that used no framework (from scratch). I limited myself to implement views and templates, but with the pass of the months I became curious so I made some research.
Now I'm checking about WSGI and how to make "do-it-yourself" frameworks. But I'm a bit curious about some things. When I was in that project 8 months ago, we used a web server, but I remember in the web there was a "web server" component too.
The component was Tornado Web Server, and this other server was nginx. Now, what's the difference between one and the other server?
And if the component (Tornado or another one) is not the only thing I need for deployment, what else I need?
To clarify:
Tornado is a Python web framework and asynchronous networking library.
That's their own definition, not mine. (https://pypi.python.org/pypi/tornado)
Tornado can function as a web server as well. Some Python web development frameworks don't really function as a web server - they need to be bootstrapped onto another library for development work. Others can function as a web server, but don't recommend it - they were designed to write code, not build it.
If you're inclined to do so, you can serve everything from Tornado directly. Most people - including the Tornado development team - have seen much better performance by putting Tornado behind nginx , and using nginx to load-balance and serve static content. http://www.tornadoweb.org/en/stable/overview.html?highlight=nginx
There are many different ways to deploy WSGI applications to the internet. Some of them include:
Directly deploy the app on port80
Use nginx/apache as a public load-balancer:
proxy connections to the app running on a local port
run the app under uwsgi, configure the public load-balancer to proxy requests to uwsgi
There are also other ways to deploy WSGI apps using gunicorn, eventlet, twisted, and countless other networking or web serving libraries.
To answer your question :
In the project you worked on, nginx functioned as a public facing web server. Tornado (most likely) functioned as both a web framework and a private web server.
Xanathos, the component you mentioned Tornado is a web server for dealing with an extremely large amount of simultaneous connections. It is built on Twisted Python, and I would not recommend using it if you are still a beginner. I might suggest that you look into Python Werkzeug as it will give you a good introduction to WSGI.
Edit:
If you want something that is a very light framework you may also be interested in Flask
Tornado is a web server for use by Python web applications.
nginx is a more generic web server that you use typically as a front in front of other webservers to do virtual hosting or other proxying. It competes primarily with Apache.
So they are both web servers, but the do completely different things.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Recommended python library/framework for local web app?
I am looking for a lightweight framework/webserver that will make it easy to develop web interfaces for some demon processes or some application that should have ideally be an desktop application.
Some examples
To organize photo/music collections, move between folders, edit meta data of those etc,
A simple to-do list/ Money manager/ Documents manager etc,
A log/textFile viewer
A page showing the status of my git repositories
I prefer server side to be python. I don't want to run a full webserver like apache. As this is going to be used similar to a desktop app, I dont need any security features that will prevent me from accessing file system or running any shell commands or accessing internet etc.,
Any suggestions?
Check bottle.py
Most frameworks will have built-in development servers, so you can still use django or some other. But if you are looking for something lightweight to do some quick project, bottle.py can be great
Werkzeug is a good choice. It's a web toolkit more than a web framework. It's very mature, and is the basis of Flask, a popular microframework.
I've developed a website using vanilla Werkzeug and it was really intuitive. It has an explicit feel to it. None of the RoR-style autoload-controller and folder logic, just a bunch of classes and modules that are really well-documented and useful.
As well as cherry.py is a lightweight framework with full server.
http://www.cherrypy.org/
CherryPy allows developers to build web applications in much
the same way they would build any other object-oriented Python
program. This results in smaller source code developed in less time.
Any Python web microframework running on any wsgi compliant Python lightweight web server will do. There are already questions on both here.
I don’t want to burden you all with the details, but basically I’m a 2nd year compsci student with no Web dev experience.
Basically I want to create a small “web app” that takes in input from a html form, have a python script perform some calculations, and re-display those results in your browser.
As of right now, I have the form and script built. However, when I try to test the form, instead of running the script, my browser tries to download it. To my understanding, this is a cgi script problem, and that I must create a web server in order to test this script.
And heres were I’m stuck. I know little to nothing about web servers and how to set them up. On top of that I’ve heard that GCI scripting is a thing of the past, and requires major overhead in order to run properly.
This leads to my questions. How do I go about completing my app and testing my cgi script? Do I install apache and mess around with it or should I be looking into something like google app engine? Are there other ways to complete this task without cgi scripts? Where do frameworks like Django fit into this?
Django, while being nice, all-encompassing and well-supported, is sometimes too much for a small web application. Django wants you to play by its rules from the beginning, you'll have to avoid things like the database and admin panels if you don't need them. It's also easier, with Django, to follow its project layout, even when it's too complex for a simple app.
The so-called micro frameworks might suit you better for your small app. They are built upon the opposite principle: use the bare minimum of features now, add more as you need them.
Flask is based on Werkzeug WSGI library and Jinja2 templating (the latter is switchable), is extensively documented (with notes concerning virtualenv and stuff) and well-suited for small and larger apps alike. It comes bundled with an auto-reloading dev server (no need for Apache on your dev machine) and Werkzeug-powered interactive debugger. There are extensions for things like HTML forms and database ORM.
Bottle is as small as a microframework can get, consisting of 1 (one) file, dev server included. Drop it into your project folder and start hacking. The built-in SimpleTemplate templating engine is switchable, but the dev server is flakier in comparison to Flask's. The documentation is less complete, and, in my opinion, the whole thing is less polished and convenient as Flask.
In both cases, you use dev server locally, and then deploy using WSGI, the server interface for Python web apps which both frameworks support. There are many ways to deploy a WSGI app, Apache mod_wsgi being one of the popular ones.
I'd totally go with Flask unless one dependency (Bottle) is better than three (Flask, Jinja2 and Werkzeug).
(There are many other frameworks as well, so wait for their users to come and tell about them. I'd suggest to avoid web.py: it works, but is full of magic, and is inelegant compared to Flask or Bottle.)
One way of getting to working webapp quickly is by first understanding, and then modifying, something like the App Engine "guestbook" example. This has the benefit that much of the otherwise necessary tedium of running a web server and setting up a database server (assuming you need persistence) is done for you. App Engine also provides a fairly flexible development environment. It's certainly not the only way to go, and I'll admit to bias in recommending it, but it's fairly low friction.
GCI scripting is hardly a thing of the past, though it's not what the cool kids are doing. CGI has the benefit, and the curse, of exposing more of the raw plumbing. It forces you to understand a lot about primitive (in the low-level sense) web architecture, but it's also a bit of a large bite to chew on if you have an immediate problem to solve that can solved by simpler means.
It appears most python web development seems to be done by frameworks these days. There are a couple reasons for this:
a plethora of mature tools. Django has built in user auth, built in database management, built in sessions, built in just about everything ORM which lets you seamlessly supports a couple databases.
Built in webservers. The larger python frameworks like django and pylons have built in webservers. Django has a very simple webserver python manage.py startserver (that simple) That makes it extremely easy to create and debug applications. It is single threaded so dropping a debugger into it is painless
Huge communities. If you have a django question it will be answered very quickly the so community is huge.
The django tutorial will introduce you to all the major aspects of development. It is only 4 pages and you will be able to get your app going a lot simpler than having to read, learn and fiddle with an apache setup.
https://docs.djangoproject.com/en/dev/intro/tutorial01/
Although django for right now might be overkill if your app is just going to be 1 form and a script to process it. Because of its seamless testing framework it is quite easy to grow any project. I have never used flask or bottle or the other microframeworks, but I would keep in mind where your project will be in the future.
As for where django fits into this, it is a full stack framework encompassing presentation (templates), data management (server orm), authentication, middleware, forms ... everything necessary to create a completely inclusive web application. Django and almost all other python frameworks implement the wsgi standard. It is an interface that allows for interoperation between webservers. http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface it is pretty dry and you will never have to interface it directly. That is what these frameworks do under the hood.
Why setup and maintain your own webserver if you can use app engine. It has an excellent SDK for testing your code. Here is an example https://developers.google.com/appengine/docs/python/gettingstarted/handlingforms
And Django you will find here : https://developers.google.com/appengine/docs/python/gettingstarted/templates
I prefer to use Jinja for templating.
Django comes with its own server, but in your case i would recommend apache and mod_python since it seems to be a rather simple site you're building.
Setting up Apache is a breeze and a simple search on the web should give you all you need.
You can find more information on mod_python here read up a little bit on it and then google after a tutorial that fits your needs.
I am wondering how to go about implementing a web application with Python.
For example, the html pages would link to python code that would give it increased functionality and allow it to write to a database.
Kind of like how Reddit does it.
If you're looking for server side programming with databases and html templates etc, I think Django is great, along with Pyramid. However, I use Flask ( http://flask.pocoo.org/ ) for this since it is easy to use, learn and deploy even though it may not have as much support as the before mentioned 2 framework since it's just a microframework, using the Jinja2 templating engine, including a development test server with it's own debugger.
On the other hand, if you're going for client-side programming (i.e. in browser implementation ) You can look up .NET Ironpython or even Brython which uses python like javascript.
You might want to check out mod_wsgi or mod_python.
What Is mod_wsgi?
The aim of mod_wsgi is to implement a simple to use
Apache module which can host any Python application which supports the
Python WSGI interface. The module would be suitable for use in hosting
high performance production web sites, as well as your average self
managed personal sites running on web hosting services.
-
Current State of Mod_Python
Currently mod_python is not under active development. This does not
mean that it is "dead" as some people have claimed. It smiply means
that the code and the project are mature enough when very little is
required to maintain it.
This is a good article from the Python website:
http://docs.python.org/howto/webservers.html
Plain CGI is a good starting point to learn about server side scripting, but it is an outdated technology and gets difficult to maintain after certain level of complexity. I would think it is no longer used in industrial-grade web server anymore. Plus you have to setup a web server and then install some module to interpret python script (like Apache with mod_python) just to get started.
I had some experience with Django (https://www.djangoproject.com/) and found it fairly easy to get started with since they come with development test server. All you need to have is a Python interpreter + Django and you can get up-and-running quickly and worry about the deployment setup later. They have pretty good documentation for beginner as well.
We have never used Python for a web site without a framework. In our case that is Django. In other words, we do not use Python for our web sites the way Perl can be used, just having Apache run a Perl script.
The recommendations you have received about Django are sound. If you go the Django route, Graham Dumpleton and the modwsgi Google group were very helpful to me. I could
not have gotten mod_wsgi deployed on Red Hat Enterprise 5 64-bit without Graham's help.
Whether you choose Django or "straight" Python, you will need to become familiar with mod_wsgi.
Good luck in quantum time, which means by now, I hope this all worked out for you.
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.