Yesterday, I posted an article about the way to installing and configuring mod wsgi. After application hooked up successfully, I faced new problem. Because I use MySQL in XAMPP for Linux package, the MySQLdb for python didn’t find mysql sock on the default path. So, you need to manually specify the unix socket.
If you run the connection manually, probably the example is just like this :
import MySQLdb
db = MySQLdb.connect( host = 'localhost', user = 'root', passwd = '', db = 'djangodb')
Then I got error like this :
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/pymodules/python2.7/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 188, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
So that means I need to specify unix socket. The syntax will be like this :
db = MySQLdb.connect( host = 'localhost', user = 'root', passwd = '', db = 'djangodb', unix_socket = '/opt/lampp/var/mysql/mysql.sock')
How I found mysql sock file path ? Just type this at terminal. And I got the path
So, I need to change django settings too. I just put socket path (/opt/lampp/var/mysql/mysql.sock) as database host. Seems ridiculous but it works properly.
It’s been so long time I didn’t yet post anything. Office movement to new place was so hectic and take much time and energy also. In this post I would share my experience in Installing and configuring Mod WSGI which is needed if you in web development using Apache as your web server and you write web apps in Python based or using Django (or else Python Web Frameworks). In this occasion, I use XAMPP for Linux instead of dependent Apache and MySQL. If you use XAMPP for Linux, you also need the developer version. Because later on, you will compile mod_wsgi using apxs and python.
Rounding a floating number is easy as pie. There are many ways to do that. Let’s see the example.
Using .toFixed
// toFixed(3)
var num = 58.8963;
var result = num.toFixed(3); // result equal to 58.896
// toFixed(2) when the number has no decimal places
num = 70;
result = num.toFixed(3); // result equal to 70.000
Error in Floating Point :
num = 162.295 num *= 100 // 16229.499999999998 num = Math.round(num) // 16229 num /= 100 // 162.29
As we see at second point, num will return exact value. So beware to use it for calculation.
Sekedar ingin berbagi tips, bagaimana cara mengambil sebuah nilai / value yang sebelumnya di parsing pada URI parameter. Misalkan dalam sebuah URI : http://localhost/myapp?id=88¶m1=robee , nah, kita mau mengambil variable param1 yang berisi nilai robee tersebut untuk diolah lagi.
Buat function :
var QueryString = function () { var query_string = {}; var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); if (typeof query_string[pair[0]] === "undefined") { query_string[pair[0]] = pair[1]; } else if (typeof query_string[pair[0]] === "string") { var arr = [ query_string[pair[0]], pair[1] ]; query_string[pair[0]] = arr; } else { query_string[pair[0]].push(pair[1]); } } return query_string; } ();
Postingan pertama di tahun 2012 ini, saya cuma ingin mendokumentasikan bagaimana cara menggunakan Django (baca : jenggo) pada sistem operasi Microsoft Windows XP. Dan sebenarnya ini juga berlaku untuk sistem operasi Microsoft Windows 7.
Sekedar informasi, Django merupakan Python Web Framework yang membantu web development berbasis Python dengan cepat. Yang pasti seperti Framework PHP, Django juga menggunakan prinsip MVC pada dasarnya, namun Django menganut prinsip DRY, yang akan membuat code lebih clean, smooth dan rigid.
Pada dasarnya, Django diperuntukkan pengembang web yang mengarah ke online newspaper atau online magazine. Namun pada kenyataannya, seperti Framework PHP (CodeIgniter dsb), Django sering juga dipakai untuk keperluan backend system.