Posterous theme by Cory Watilo

Filed under: Web Site

Django: CSRF verification failed. Request aborted.

I just recently upgraded to Django v1.2.3. I'm really diggin' this new version so far. The framework has significantly matured now. There were no major problems with porting my existing sites except when I went into the CMS, would make an edit and then tried to save any changes to the db and I would get the following error message: "CSRF verification failed. Request aborted." I had NEVER seen that error before and no idea what to do. As with most things related to Django, (and really almost all open source projects), there was no documentation on this error. Not in the release notes. Not in the online documentation. Nowhere! I was foreseeing a long night ahead of me trying to get to the bottom of this error. So after some digging around I came across this blog entry from Jordan Messina that solved it for me. I sharing the solution here. Simply edit your settings.py file and add the following lines to the MIDDLEWARE_CLASSES section: 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfResponseMiddleware', So it should now look like this: MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfResponseMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ) Kill the server. (If it's running.) Run "syncdb". Run the server and voila... when you save all should be good with the world. This saved me hours of my life. (Your mileage may vary.)

iPhone OS v3.0 Features - Lotta New Goodies

I was really excited by the news of the new iPhone OS v3.0 announced last week. Copy-and-Paste aside, there are a lot of less-talked-about features that I find pretty cool and crucial to the advancement of the platform:

Peer-to-Peer Connectivity over Bluetooth

This is a feature that I thought seemed so obvious to have baked in. With Peer-to-Peer connectivity, you are now given the ability to communicate with other local phones WITHOUT having to pair with them in order to do it. (Like you have to when you use a Bluetooth mouse or headset.) This is great for applications that would need to share pieces of data for short periods of time. Or games that share proximity for a short period of time. I'm just starting to mess with this now so I am really anxious to see what the full line of functionality that is provided for is.

In App Purchase With this feature, in my mind, the iPhone grows up. Now is when e-commerce will really begin to take off with the device. I also feel that now we will *really* begin to see some money being made in the mobile arena. In App Purchasing means that you can have fully-functional mobile e-commerce without having an entire website and all of the complexities that it involves. (Yes, I realize I am a developer of web-based e-commerce solutions. We plan to make some of that money.)

iPhone Core Data Of all the new functionality and features presented... none were more significant, (for me), then Core Data now being available on the iPhone. For those of you less geek-inclined... Core Data (http://developer.apple.com/macosx/coredata.html) is a method for managing the data model for MacOSX applications. Up until now you had to write your own methods for handling things like data relationships, the adding, updating and deletion of records.

As anyone who has had to build an application with persistent data will tell you, while it's awesome to be able to develop using SQLite and plists on the iPhone, it does not compare with being able to code against an abstraction layer that just works! So I'll take the added complexity associated with Core Data any day of the week.

In Summary I love developing for the iPhone and the Macintosh. The iPhone OS v3.0, even in BETA, is such a huge leap forward. Not just for the platform, but those who write software for the iPhone and have been waiting for Apple to enable developers to really take their applications to a level above "cute" or "neato" or niche.

The only outstanding issue I see before Apple is it's whole approval/review/rejection process for iPhone applications. As a developer, it is a really frustrating process. Their methods just seem so arbitrary. (One app gets rejected. Similar app, different developer and it get approved.) I would be willing to forego new features and frameworks in the short-term in order to give Apple more time to create a more thoughtful and predictable review process with metrics and benchmarks to boot.

Configuring MySQL-Python on OSX Leopard

At WebSight Design we try to remain technology-agnostic. (The right tool or language for the job.) Having said that, we are primarily a PHP shop. However, with the launch of the Google App Engine, we've been looking seriously at Python. In recent years, I have become a big fan of development frameworks so to aide me in learning the ways of the snake, I have been using the Django framework. Getting it all setup wasn't difficult. The Django installation is very easy. I started to get errors when I was trying to get my models working when I ran manage.py syncdb. Come to find out that I needed the MySQL-Python library installed to work correctly on my OSX Leopard machine. Most everything that I illustrate below is to be executed from the command-line. So if you are not familiar with working in the Terminal app, this post is gonna suck for you. So here is what I did to get it working: First, download MySQL for Python http://sourceforge.net/projects/mysql-python for me it was MySQL-python-1.2.2.tar Unpack it: tar -xzf MySQL-python-1.2.2.tar Change to the directory that is created: cd MySQL-python-1.2.2 Next, locate your "mysql_conf" file. locate mysql_conf Copy the location of this file so you can use it in the next few steps. Next, you need to edit the "site.cfg" file and add the path to your "mysql_conf" file. mysql_config = "YOUR_PATH_GOES_HERE" Also, (very important), change the line that reads: threadsafe = True TO threadsafe = False Save and exit the file. Now, compile and install the library: python setup.py build sudo python setup.py install NOTE: You may need to run "python setup.py clean" if you previously tried to build and install the library. Next is the *really* important part. After I kept getting errors trying to run the Python server I found the missing piece on the ProjectMouse.org site. The key is, you need to create a symbolic link in the location that Python is expecting to find MySQL. This should be a link to the MySQL library that your computer is setup to use. See here: sudo mkdir /usr/local/mysql/lib/mysql/ sudo ln -s /usr/local/mysql-5.0.41-osx10.4-i686/lib/libmysqlclient_r.15.dylib /usr/local/mysql/lib/mysql/libmysqlclient_r.15.dylib NOTE: "mysql-5.0.41-osx10.4-i686" is where MySQL is installed on my machine. Change this to the location specific to your computer. Finally, import MySQLdb into Python and test your configuration: python import MySQLdb NOTE: You should not see any errors or warnings. Hit "Ctrl+d" to exit the interepter. Now go back and run manage.py syncdb again and you should not get any errors.