157 + 486 = 157486!!
Posted by Uberto Barbini on March 23, 2008
At least according my first Django site!
(bug fixed in version 2.0 almost 12 seconds later…)
Anyway as little spike I created a (very useful) site that adds two numbers, for example
of course you’re free to change the numbers. Not sure how long I’ll keep it running up.
What’s the point? Actually I wanted to deploy something on my virtual host but creating this site took me 5 minutes and 8 lines of code.
from django.http import HttpResponse
def plus(request, n1, n2):
n1 = int(n1)
n2 = int(n2)
html = "%s + %s = %s" % ( n1, n2, n1+n2)
These are 7, the last one is in the urls.py (one of the 4 files automatically created by django for a new project).
from django.conf.urls.defaults import *
from views import *
urlpatterns = patterns('',
# Uncomment this for admin:
# (r'^admin/', include('django.contrib.admin.urls')),
So, all in all it’s not such a big effort! I know that maybe with Rails I could do the same in half the lines , you could do it in Python too for what it matters.
Anyway I’m still fond of Python values (aka “import this”) and Django is really really elegant.
I haven’t yet configured postgreSQL on the server, so you have to wait a little before seeing something interesting.