My first web application (Python): use CGI or a framework like Django?

I don’t want to burden you with all the details, but basically I'm a 2 year old compsci student with no experience with web developers.

Basically, I want to create a small "web application" that accepts input from an html form, ask the python script to do some calculations and redisplay these results in your browser.

As of now, I have a form and a script. However, when I try to validate the form, instead of running the script, my browser tries to load it. As far as I understand, this is a cgi script problem and that I have to create a web server to check this script.

And so I was stuck. I know little about web servers and how to configure them. Ive also heard that GCI scripts are a thing of the past and require a lot of overhead to work properly.

This leads to my questions. How can I end my application and test my cgi script? I install apache and communicate with it, or should I look at something like a Google engine. Are there other ways to accomplish this task without cgi scripts? Where do frameworks like Django fit into this?

+7
source share
5 answers

Django, being nice, comprehensive, and well-supported, is sometimes too much for a small web application. Django wants you to play by your own rules from the start, you have to avoid things like the dashboard and the admin panel if you don't need them. It is also easier, with Django, to follow its project layout even if it is too complicated for a simple application.

So-called microarchitectures may work best for your small application. They are built on the opposite principle: now use a minimal set of functions, add as many as you need.

  • Flask is based on the Werkzeug WSGI library and the Jinja2 template (the latter can be switched), widely documented (with a note on virtualenv and materials ) and is well suited for small and large applications. It comes complete with a dev auto-reboot server (no need for Apache on your development machine) and an interactive debugger with Werkzeug support. Extensions exist for things like HTML forms and the ORM database .

  • Bottle is no less than a microcard consisting of 1 (one) file, including the dev server, can receive. Move it to the project folder and start hacking. The built-in SimpleTemplate template engine can be switched, but the development server is more fragile than Flask. The documentation is less complete, and, in my opinion, all this is less polished and convenient, like Flask.

In both cases, you use the dev server locally, and then deploy using WSGI, the server interface for Python web applications that support both frameworks. There are many ways to deploy a WSGI application; Apache mod_wsgi is one of the most popular.

I would go completely with Flask if only one addiction (Bottle) was not better than three (Flask, Jinja2 and Werkzeug).

(There are many other frameworks, so wait until their users come and talk about them. I suggest avoiding web.py : it works, but it is full of magic and inelegant compared to Flask or Bottle.)

+9
source

One way to quickly get to working Webapp is to first understand and then change, for example, the App Engine guestbook application. This has the advantage that most of the unnecessary result of the web server and setting up the database server (provided that you require persistence) for you. App Engine also provides a fairly flexible development environment. This, of course, is not the only way to go, and I will admit bias by recommending it, but it’s pretty low friction.

GCI scripts are unlikely to be a thing of the past, although this is not what cool kids do. CGI has the edge and the curse to expose more raw plumbing. It makes you understand a lot about primitive (in a low-level sense) web architecture, but it is also a bit of a big bite to chew on if you have an urgent problem to solve that can be solved using simpler means.

+4
source

It seems that at present, most python web development seems to be running frameworks. There are several reasons for this:

  • many mature tools. Django has a built-in user auth built-in to database management, built-in to sessions, built-in to almost all ORMs, which allows you to easily maintain a couple of databases.

  • Embedded web server. Large python frameworks like django and pylons are built into web servers. Django has a very simple python manage.py startserver web server python manage.py startserver (this is simple). This greatly simplifies the creation and debugging of applications. It is single-threaded, so dropping the debugger into it is painless.

  • Huge communities. If you have a question about django, it will be answered very quickly, so the community is huge.

The django tutorial will introduce you to all the basic aspects of development. These are just 4 pages, and you can get the application a lot easier than reading, learning and tinkering with apache settings. https://docs.djangoproject.com/en/dev/intro/tutorial01/

Despite the fact that django may now be full if your application just has 1 form and a script to process it. Due to its seamless testing system, it is quite easy to grow any project. I have never used a flask or bottle or other microframes, but I will remember where your project will be in the future.

As for where django fits into this, it's a complete stack structure, including presentation (templates), data management (orm), authentication, middleware, forms ... everything you need to create a fully inclusive web application. Django and almost all other python platforms implement the wsgi standard. This is an interface that allows you to interact between web servers. http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface , this is pretty dry and you will never have to contact him directly. That's what these frames do under the hood.

+3
source

Why set up and maintain your own web server if you can use the application engine. It has an excellent SDK for testing your code. Here is an example https://developers.google.com/appengine/docs/python/gettingstarted/handlingforms

And you will find Django here: https://developers.google.com/appengine/docs/python/gettingstarted/templates I prefer to use Jinja for templates.

+2
source

Django comes with its own server, but in your case, I would recommend apache and mod_python, since it seems like a pretty simple site that you are building.

Setting up Apache is a breeze, and a simple web search should give you everything you need. You can find more information about mod_python here to read a little about it, and then google after a tutorial that suits your needs.

-one
source

All Articles