September 3, 2010

How To Run Sandboxed Django Sites in Production

Recently, I moved all my sites from a dedicated server to a great VPS over at SliceHost. I took the opportunity of “the big move” to fix an ongoing problem I’d had, which was that all four of my Django sites were using the same libraries.

Ouch! That meant that I couldn’t update any of my sites without updating all of them, or at least retesting all of them.

This article will explain how I sandboxed my Django sites, so that all of them have their own versions of the appropriate library, and how I have them all running on the new production server.

[Read more...]

Technorati Tags: , , ,

Speaking at DjangoCon 2009

I’m going to be presenting at DjangoCon 2009!  The 45 minute presentation will be on the advanced use of Django signals to promote reuse.

I’ll be using Satchmo as an example of how to create very useful custom signals to allow for some quite complex customizations. If you want a copy of the presentation, please sign up below and I’ll send it after the convention.

Django, the web framework for ponies with magical powers

Django Pony

Last year at DjangoCon, one of the most interesting sessions was the one where people presented their “pony requests”, and made a case for their pet feature to be built into Django.

Shortly after that, the first logos for the Django Pony began to appear, followed by the inevitable (in retrospect) djangopony.com.

This morning, I discovered that NASA uses Django and even has a Django Pony page.

Fly, little pony, spread your meme wide!

[tags]django pony, django, djangocon[/tags]

A short example using django-app-plugins

At Djangocon a couple months ago, I was intrigued to hear about Django App Plugins. This small app adds the ability to make mount points in your Django templates.

That way, you can have your apps insert text into your templates just by referencing the mountpoint in the template. This allows you to have apps which possibly aren’t central to your main application add text which you wouldn’t want to put into the default template.

Unfortunately, there is absolutely no documentation, so I spent the evening working out how to get this to work. There are tons more options than what I’ve figured out, I think a simple example is much better than no documentation at all.

[Read more...]

Technorati Tags: , , , ,

Setting up SSL for Lighttpd/Django

My latest client Farinaz Taghavi is finally in beta on her site, and one of the last steps to push her live was to set up SSL for her.

Luckily, I’ve done this a number of times, so it was quick and easy to do, but still I had to refer to various reference sites and remember exactly what I do differently than some.

First off, I use the Lighttpd configuration I describe in "Django and Lighttpd Configuration for smooth SSL", I don’t have any need to vary it much from what I did for my other site, but since I am using Satchmo for my ecommerce engine on this one, I can’t have a separate domain name for my secure and non-secure domains. In other words, I want both http://farinaz.com and https://farinaz.com to work.

The changes are simple, but since it is slightly different, you can download it and modify for your own use: lighttpd_ssl.zip

In that file are the two very important lines:

ssl.pemfile = "/etc/lighttpd/ssl/farinaz.com/farinaz.com.pem"
ssl.ca-file = "/etc/lighttpd/ssl/farinaz.com/farinaz.com.crt"

The rest of this article will discuss how to acquire those files.

Creating the Certificate

1. Create a working directory. I always put them in “/etc/lighttpd/ssl/servername

mkdir -p /etc/lighttpd/ssl/yourserver.com
cd /etc/lighttpd/ssl/yourserver.com

2. Create your server key, and then (optionally) remove the password from it. The only critical question is “common name”, which must be the domain name you want to secure. In our example, “yourserver.com”

openssl genrsa -des3 -out yourserver.com.key 1024
openssl rsa -in yourserver.com.key -out yourserver.com.nopass.key

3. Create the CSR (Certificate Signing Request) that you’ll be using at the certifying authority to get your cert.

openssl req -new -key yourserver.com.nopass.key -out yourserver.com.csr
cat yourserver.com.csr

4. Copy the text to your clipboard. It will look something like this:


-----BEGIN CERTIFICATE REQUEST-----
MIIBrzCCARgCAQAwbzELMAkGA1UEBhMCVVMxDzANBgNVBAgTBk9yZWdvbjERMA8G
A1UEBxMIUG9ydGxhbmQxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0
[... and so on ...]
2JwW20fix2pFjK22E+jUvNh25cTRWpUKeTt5OEoE3hgkPZCjZPuzvXt7dw5N1CBv
1a9vX8LRMPRd+TtlOEBHhNZ2DLSkzAvTg4RI+1uPLN3KBpRp9FCTaPEmeuLfMBwl
Y7Se
-----END CERTIFICATE REQUEST-----

5. Go to a good cheap certificate source. I like to use Name Cheap since they are in fact cheap, their control panel is very usable, and they are not underhanded in business dealings unlike the infamous GoDaddy. (I currently have 49 domains with them!) Namecheap has SSL certs for as low as $12.88 per year.

A short aside. There is no reason I can see for 99% of all site operators to get anything more than the cheapest possible cert from RapidSSL. Ignore all the sales hype. The simple fact is that no one except extreme geeks even know or care about levels of certification, the vetting process, or any of that. It is simply not a factor in purchasing decisions from anything I’ve ever seen, and I used to work for a company that sold expensive certs!

6. After you purchase your cert, the site will ask you what type of system you have. I’ve never seen Lighttpd listed as an option, so you should select “Apache + OpenSSL”

7. Next it will ask for your CSR. Paste in the text you copied in step 4.

8. Make sure you can receive email at the address where the certificate authority will send the confirmation! Wait for it, and click the confirmation link.

9. Wait a few minutes to get your cert.

10. Copy the text of the cert to a file on the server. I just use emacs and paste in the contents of the cert I copied from the email. Save it as “yourserver.crt”.

11. Finally, create your pem file.

cat yourserver.com.nopass.key yourserver.com.crt > yourserver.com.pemchmod 0600 yourserver.com.pem

12. Verify that lighttpd has SSL.

/usr/local/sbin/lighttpd -v

It should say something like “lighttpd-1.4.11 (ssl).” If it doesn’t then you need to recompile it. Use the instructions on cyberciti.biz for that if you need it.

13. restart the server.

/etc/init.d/lighttpd restart

Done. This takes me about 15 minutes, most of that waiting on emails.

[tags]ssl,lighttpd,satchmo,django[/tags]

Released InvisibleCastle

I’m pleased to announce the release of my latest Django site, Invisible Castle. This is a Play-by-post gaming site for RPG players, which gets over a million hits a year.

This is an absolutely huge update from the previous codebase. Before it was written cgi-style with custom cgi code and Cheetah Templates for page layout. As a learning project, and to make it tons more maintainable, I ported the whole thing to Django.

The biggest challenge was converting all the old data, several million rows. It took almost a full day of running my crazy convert script, which I wrote using SQLAlchemy to pull the old data, and direct Django Object creation to insert the new objects.

The single best advantage of the upgrade is that it no longer acts like a pile of razor wire. I can update, change, or modify any part of the code, run regression tests, and expect it to be just fine. Before it was all too easy to break it in a non-obvious way.

Thanks to Herbert Poul for his Sphene Community Tools Django forum code. It is a nice little codebase to host my new forums.

[tags]python,django[/tags]

Linux.com article

I’m quoted heavily in a Linux.com article about http://oohgabooga.com, the webstore I launched this summer.

If you want to hire me for your dream webstore, I’d love to talk to you. Please send an inquiry through http://solidsitesolutions.com.

[Read more...]

Trackbacks on Banjo

Working on Banjo Blog, nearly the only thing remaining before my initial release is a trackback/pingback system.

Oddly enough, there isn’t any django trackback app in the wild, at least not any I could find. So, I looked around and found only half-written stuff, hacky garbage and tblib, which is too old, not Django aware, and GPL. Banjo is BSD and it is going to stay that way, thank you.

So, I wrote my own.

[Read more...]

Importing WordPress to Banjo

Thanks to Andy C I’ve finished the WordPress import script for Banjo.

That article gives instructions for direct SQL loading of a somewhat different blog database. I couldn’t use it directly for Banjo, partially because I’m through with using MySQL. I just can’t take all the UTF problems any more. I’ve gone all PostgreSQL all the time.

So my solution needed to speak MySQL and then directly create objects in Django. That way it could be used for any target database.

[Read more...]

Banjo Blog nearing 0.1 release

BanjoI’m nearing release 0.1 for Banjo, a blog app written in Python on the Django framework. If you look at the mailing list, you’ll see plenty of people asking about a blog app, and the standard reply is that it is just so easy, almost trivial, to write your own that there is not much call for such a package.

I disagree

I really don’t agree with that logic although I do understand it. Blogs look simple, and stripped of everything else, they really are simple. Basically they are just reverse chronological posting of text on a page. No biggie, at least at first or second glance.

But the trick is in the phrase “stripped of everything else.” Once you start considering the features commonly available in blog apps, it gets quite a bit more complex:

[Read more...]