Django — ‘NoneType’ object has no attribute ‘has_header’

‘NoneType’ object has no attribute ‘has_header’

on if not response.has_header(‘ETag’):

This error appears if you don’t return anything from your view.

return direct_to_template(request, "template")

I wonder if this is a new error message? I recall a more specific error in my previous version of django, something along the lines of “Your view didn’t return anything!”

Django Plugins — Django South for Database Migrations

django-south

Database migrations handled easily. Now I can add the migration files that are generated to the GIT repository PER-BRANCH and grab them on the production server when the time comes.

UPDATE 9 months later when I realized this is one of the top results for django south.

I might as well write a simple tutorial on how to use it. Read the South docs, but in as few lines of code as possible, here’s what to do:

pip install South


### modify settings.py and add 'south' to INSTALLED_APPS


python manage.py syncdb 
# adds south tables


python manage.py schemamigration myapp --initial
# sets up your app for the first migration.


python manage.py migrate myapp --fake 
# "fakes" a migration because you will get an error if you try to migrate
# from an existing database setup. You will get a "table already exists" error otherwise.


### modify your app models, then auto-create a migration


python manage.py schemamigration myapp --auto
# this will auto detect the changes


python manage.py migrate myapp
# will apply new migration.


git add myapp/migrations/ 
# add migrations to version control


### download migrations on remote machine, and simply type in 
python manage.py migrate
# note: this is after faking the first migration if the database exists.

Hope that helps!

Aptana 3 — Python Support / PyDev on Aptana 3 Beta

If you’re running Aptana 3 Beta Windows, PyDev isn’t in the default list of addons via their package installer.

To install it, you just need to add the PyDev site to the installer.

  1. Go to Help > Install New Software
  2. Click “Add”
  3. Fill in PyDev for name, and http://www.pydev.org/updates/ for the location.
  4. Find PyDev by typing Py in the filter text
  5. Check PyDev and be on your way

Git — Change Branch for Uncommitted Working Copy

Say you’re working on branch x and you started to make some changes.

You suddenly realize you meant to be on branch master.

You can’t switch branches w/o committing.

Here’s how to switch:

git stash
git checkout master (or whatever branch you meant to be in)
got stash pop

Resolve the conflicts you get, and you’re good to go.

Jquery — Selectors. Select one child element

Finally, found a reference to my favorite method.

I needed something that traverses the DOM DOWN, not UP, but behaves like $.closest and $.parents

That is: $(TYPE, $JQUERY)

For an image inside a div you’re clicking:

$("div").click(function() { 
   $('img', this).show();  
});

Linode — filesystem is read-only after cloning

Quick tip here for those who just cloned a linode and their newly cloned filesystem says it’s read-only.

As a relative newblet to Sys Admin stuff, I submitted a ticket and got an answer in 30 mins w/ the solution.

Indeed, I did a clone while the source system was online.

The fix

http://library.linode.com/troubleshooting/finnix-recovery

  • Make a new boot configuration in the linode manager.
  • Load the finnix recovery kernel, mount the 3 disks as shown in the image. The finnix partition, your partition, and your swap.
  • Don’t forget the initrd image at the bottom.
  • Boot the system
  • Launch ajax console
  • Type in..
fsck /dev/xvdb
#note: xvdb is the second slot in the mounted disks in your setup. xvdc if you used the third, dvdd if fourth, etc.

and if you don’t want to type yes over and over for a few days, append a -y to it.

fsck /dev/xvdb -y

Reboot your initial configuration, and you’re good to go.