If it ain’t broken don’t fix it

Yet another worthless blog… by Uberto Barbini

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

http://uberto.user.openhosting.com:8000/calc/156/plus/418/

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
import datetime
def plus(request, n1, n2):
n1 = int(n1)
n2 = int(n2)
html = "%s + %s = %s" % ( n1, n2, n1+n2)
return HttpResponse(html)

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('',
(r'^calc/(\d+)/plus/(\d+)/$', plus),
# 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: