Running django on OSX
I just finished a very nice django tutorial and everything went smoothly. One of the first parts of the tutorial is that it says not to use my example server product in production, so my first thing after the tutorial was to try and run my application on apache.
I am running OSX 10.5 and have standard apache (which refuses to run python) and MAMP (which usually allows it to be used in cgi-bin). The problem is I have no idea which script to call to, in the tutorial it was always localhost: 8000 / polls, but I don't know how it was meant to map to a specific file.
Am I missing something blatantly obvious about what to do with the .htaccess file, or the tutorial doesn't explain how to use it elsewhere?
a source to share
You probably won't find much joy using .htaccess
to configure Django through Apache (although I admit you could probably do this if you were defined enough ... but for production I suspect it will be harder than necessary). I am developing and running Django on OS X and it runs pretty smoothly.
The secret is that you must configure httpd.conf
to pass requests to Django using one of three options: mod_wsgi
(most modern approach), mod_python
(second option, but works fine on OS X Python 2.5), fastcgi
(well ... if you have to match your production environment).
The Django deployment docs have good tips and instructions for all three options.
If you are using the default OS X apache install, edit /etc/apache2/httpd.conf
with directives found in the Django docs above. I can't speak for MAMP, but if you build Apache from source (which is so simple on OS X, I really wonder why anyone is bothering with MAMP ... my uncertainties show up), edit /usr/local/apache2/conf/httpd.conf
.
a source to share
If you plan on working with OS X, you might not want to worry. If you do, go straight to mod_wsgi. Don't worry about mod_python or older solutions. I made mod_python on Apache and while it works fine it took many hours to set up.
Also, just to clarify something based on what you said, you won't find a mapping between the url (like / polls) and the script being called. Django doesn't work like this. With Django, your application is loaded into memory, waiting for requests. As soon as the request comes in, it is sent through the urlmap you created at urls.py. It boils down to calling a function somewhere in your code.
So for a web server like Apache, you need a module like mod_wsgi that gives your application a place in memory to live in. Compare this to something like CGI, where the web server executes a specific script upon request at a location physically mapped between the URL and the filesystem.
I hope this is helpful and doesn't tell you what you already knew. :)
a source to share
If you plan on running it for production (or non-development), another option is to get rid of Apache and go with something lightweight like nginx. But if you're doing development, you'll want to stick with the embedded server and PyDev in Eclipse. It is much easier to step through the server code one at a time in the Eclipse debugger.
Installation instructions for nginx / Django are here: http://snippets.dzone.com/tag/nginx
a source to share
Another option is to consider using a virtual machine for your development. You can install the full version of any OS that will run your production server - say Debian - and run Apache and DB in a virtual machine.
You can connect to a virtual drive in Finder, so you can use TextMate (or whatever) on OSX to edit.
I had good experiences with VMWare Fusion.
a source to share