Running manage.py through SSH

I have been having the problem trying to run manage.py on a live server.

Firstly as it is on linux, it is necessary to prepend windows style statements with python.

python manage.py runserver

instead of

manage.py runserver

Also, make sure you are using the correct version of python. E.g:

python2.7 manage.py runserver

If you don’t you will get an error about trying to import django.core.management :

File “manage.py”, line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named django.core.management

Database synchronisation – Django

SyncDB does a great job of adding new models as tables to the database.  It doesn’t however update the structure of the database if changes have been made to the model.

South does however (there are other projects, but South appears to be the best).

Django Server set up – useful links

I have used Webfaction to get my django site online. They seem very reasonably priced, have servers in Asia (as well as US and UK) and everyone seems to recommend them.

They set the django app up for you, which was quite reassuring on my first release. They create an initial Django project, but you can easily change the app to point at yor own project file by following their instructions.

Everything seemed to go very small issues (and the issue with static files below).

1. On Webfaction the default version of Python appears to be 2.4, so easy_install was installing modules as python 2.4 causing an issue when installing south, the accepted answer on this question sorts things out).

2. When adding my project as the main website, it caused Django to give a 500 error message. On inspecting the log files, I noticed that the module for my app could not be imported. Fixed by editing the python path variable in the httpd.conf file located in the  <your app name>/apache2/conf directory.

Static Files

Having skim read the Django documentation when getting static content working on my dev server, I was shocked to find that none of my static content worked in the live environement.

If you read the static file documentation carefully it says:

  • The development server serves static content to reduce hassle.
  • In a production environment, Django is not optimised for serving static files. Something like Nginx can do it much better. So Django is set up not to serve these files.
  • They provide the tools to make this easy (collectstatic).

You therefore need to set up your own server for static content. This is a great tutorial for setting up Nginx on Webfaction – worked first time (although I didn’t need to do step 4 – as the update indicates it is already installed).

Once that is done, and you have checked it is working, put a couple of test files in the html directory of the Nginx installation and they are served as expected.

To put all your static files in there, edit your django settings file and change the STATIC_ROOT setting to the absolute path of your Nginx Html files. Then run the collectstatic command with manage.py and all your applications static files will be transferred.

MySQL – add user error

I have just installed MySQL for the first time, and I am just getting started setting up a new database.

When adding a user to a MySQL server using the command:

INSERT INTO mysql.user(User, Host, Password) VALUES('username', '%',
Password('password'))

I found that I received the error:

Field ssl_cipher doesn't have a default value.    1364

Looking on the MySQL bug list, it appears that plenty of people are having the same problem on windows, but there was one solution suggested that fixed the problem:

INSERT INTO mysql.user(User, Host, Password, ssl_cipher, x509_issuer, x509_subject)
VALUES('username', '%',
Password('password'), '', '', '')

This worked perfectly.

As we are just inserting empty values into those columns, I am sure that the table could be altered to have a default value of an empty string for each of the three additional columns. a puzzle for another day.

Running Python scripts on Windows

Having run most programs direct from within visual studio, it has been a rare occassion that I have had to work from the command line.

Starting Python development I have downloaded eclipse and pyDev and am ready to start my first python project.

I found a tutorial that goes through in great depth about how to run .py files from the command line in Windows. It also appears to cover how to build packages for distribution, and setting up web apps. All things that are likely to come in useful later on.

Small Caps with css

Css can be a little odd at times.

I quite frequently use text-transform for uppercase and lowercase elements. However I wanted to apply small caps to a heading in a new website. For some reason it is not applied as a text-transform, but a font-varient. The syntax is:

font-variant: small-caps;

Note that some fonts don’t have a small-caps version and therefore will not be displayed in the browser.

While looking into this. One of the other options that I noticed for text Transform is capitalize. Which makes the first letter of each word uppercase. Very useful for displaying names that have been user entered.

Image Annotation

I don’t currently have a copy of snagit on my temporary work machine. I was looking to annotate a couple of screen shots of a website design, and I just can’t abide MS Paint.

I found szoter which did the trick in this instance. There were a couple of issues with it:

  1. I had to manually upload the screen shots to it and then download them at the end. There is a desktop application that you can download free of charge. Requires Adobe Air.
  2. The editable area was quite small (smaller than the screen shot itself). Perhaps that is just the free version.

Other than that a great tool, will use again.