I’ve been doing quite a lot of development lately, on various projects, and have been making great use of Vagrant for isolated development. As such, I need to write provisioning scripts so that each machine can be built exactly as the production machine will be. I’ve tried Puppet once but it was far more than what I needed, so I just settled with using a shell script provisioner. Just a basic bash file with a bunch of apt-gets, pips and what not. Most of my projects require a database so MySQL it is. The issue I had was automatically installing MySQL without being asked for a password (as the provisioner is non-interactive). One amazing way I’ve found is issuing these commands before the apt-get (or tasksel) commands to install MySQL
I am getting pretty close to deploying m webap and am currently looking into ways to monitor exceptions once deployed. Django has the ability to email whenever it encounters a 500 error. I don’t really want any emails being sent out (yet) so I decided that I should probably just stick with local mail delivery until such time that I want to be notified right away of a problem. Read the rest of this entry »
Very quickly, I’d like to introduce to you my newest github project – django-boilerplate-layout. It is my hope that for each new version of django, you can check out this project layout and just start coding. More info on what this project is on the README.markdown
I am working on a Django-powered website, a website with no actual login of it’s own. I am using 3rd parties (Facebook/Twitter/etc) to provide authentication for my users. The issue I ran into is, what happens if a user goes to a url that is protected with a @login_requred decorator? Well, it should be simple – Django redirects the user to the supposed login page, with a parameter of next=/some/url/to/go/to. Since my app doesn’t do the login itself, the user then clicks on which third party service they wish to authenticate against. The user is taken through the third party’s authentication workflow and redirected back to my site. The problem here is that the “next” url parameter is lost in the process. I thought I would need to write a @login_required_session decorator, which would be less than ideal if my app then uses built in views with the @login_required decorator.
Just a quick post to link (one of my) works in progress – django-twitter-oauth that I forked on github. It is a work in progress as I am using it on another project I’m working on currently so, hopefully, this app can only get better over time. There are a few things I may want to change (caching the access token in the session instead of always going to the DB) and, really, this has not been tested on MySQL yet (I am using sqlite3 for dev), but it should work. Works well so far. Only a few problems I have yet to start working on (off the top of my head, random BadStatusLine exception every once in a while, mainly) .
I will try to update my blog whenever I update the app with what I changed, but we’ll see.
This will be a really quick post since, for whatever reason, I could not find this information out easy on the internet. The only reason I was able to find it is due to my great and good friend, Andres Buritica’s help. Starting a Django project, then an app gives you a models.py which Django expects to house all the models. This does not seem like the best of ideas, so obviously I want to split up the models into their own files in a specific model directory. To accomplish this, you must do two things:
Create a meta class for the model with a field “app_label” being set to the name of your app
In your __init__.py file, import that model.
For example, if you started an app by typing out ‘python manage.py startapp foo’, you can delete your models.py file, replace it with a directory named models (what I do), and inside have an __init__.py and Bar.py files.
in Bar.py:
from django.dbimport models
class Bar(models.Model):
bar = models.TextField(blank=False)class Meta:
app_label = "foo"
then in __init__.py:
from Bar import Bar
This also goes for other things specified outside of the Django “norm” I guess?
If I wanted to associate Bar with the admin, I create a subdirectory inside my app named admin, and inside it I have
BarAdmin.py
from foo.modelsimport Bar
from django.contribimport admin
admin.site.register(Bar)
Inside the __init__.py for the admin subdirectory, you’d have:
import BarAdmin
Now I could be doing this all wrong but this is the only way I managed to get everything working. If there is a better way to do this, I am all ears. To you Django/Python professionals out there, this may be common knowledge but I am noobing it up right now trying to better learn Python and Django.
As I may have pointed out in a previous post, I’ve switched all my non-server computers over to OSX. My desktop is OSX and dual boots Windows (for very few things). My latptop, my development machine, dual boots OSX and Linux. Each instance of OSX has Virtual Box and Windows XP as well as Linux, the mentality that for simple Windows and Linux things where OSX wouldn’t/couldn’t work, I can use a VM. For 99% of the time, that works. Ultimately I switch into the secondary OSes only when I need to access the hardware natively.
One issue I’d run into switching between OSX and Linux for development - and one thing that really bothered me – is OSX’s home directory is /Users while any Linux box is /home. Call me lazy for not having a better way to manage configuration files but I didn’t want to manage configuration files. I finally decided that my OSX box should probably match my Linux box in terms of directory structure, at least superficially. I backed up the current /home directory on OSX and created a symlink to /Users so that /home -> /Users.
I don’t know if this is a bad thing or not, so try this at your own risk, but so far for me, I like it. I don’t know what’s taken me so long to do this.
These commands backup your current /home to /home_bkup, in case you ever need it again. Why? I don’t know.
Few reasons why I haven’t updated this with any meaty updates:
I’ve taken time off to do the life thing. Cliche but needed.
Now that I’ve got back into developing software, I am trying new things out: Python/Django and Javascript
Now my Javascript experience has always been very poor but lately I’ve been finding videos that talk about Javascript and it is really getting me interested and excited about the language. The two so far I’ve found are:
JavaScript: The Good Parts talk by Doug Crockford
and the 10 Things I Learned from the jQuery Source by Paul Irish:
Now let me be honest: I’ve never been a fan of front end development. HTML sucked, Javascript wasn’t close to my favorite (I’d much rather code up some assembly than touch Javascript) and their interaction with each other was dirty, at best. With the dawn of HTML5, I’ve become interested in HTML again and viewing (or, trying to view) the Javascript source of the very prominent websites got me interested in Javascript. The real turning point for me was watching Paul Irish’s10 Things I Learned from the jQuery Source. That video, really, has turned me around on the power of Javascript.
I’ve always loved Google Chrome, since I first got my hands on it, but there were always so many things that I depended on in Firefox did but Chrome didnt – Live Bookmarks and Adblock mainly. Today marks the day that I’ve converted to using Chrome exclusively and here’s why.