Installation

as root:

  easy_install pip
  pip install virtualenv

As normal user:

$  virtualenv projectname
$  cd projectname
$  source bin/activate
(projectname):$ pip freeze
(projectname):$ pip install django==1.6.7
(projectname):$ pip install south django-registration stripe
(projectname):$ django-admin.py startproject djlogin

Just a bunch of code i will probably not remeber

  python manage.py startapp myapp
  python manage.py syncdb
  python manage.py runserver

First command creates app myapp, second creates tables in database according to models.py, and the third one starts the server at port 8000.

In case you want to access the server from outside:

  python manage.py runserver 0.0.0.0:8000

Best editor for django/python development

South

  • great tool for migrating & altering DB

To start using south…

Make sure your django tables match your current database tables exactly - if you planned to add or remove columns, comment those out and run:

./manage.py schemamigration myapp --initial name_of_migration
./manage.py migrate myapp --fake

Make changes to your django model and then run:

./manage.py schemamigration myapp --auto
./manage.py migrate myapp

Vim python autocomplete

Python source code encodings

If UTF-8 source file encoding is needed …

# -*- coding: UTF-8 -*-

…put this on the beginning of the source file.

Database settings

MyISAM storage:

mysql>>> ALTER TABLE search_ftext ENGINE = MyISAM;

Create fulltext index

mysql>>>  ALTER TABLE search_ftext ADD FULLTEXT (text);

if Django keeps falling after editing in admin - convert table DjangoAdminLog to the same collation as other tables:

alter table auth_user_user_permissions convert to character set utf8 collate utf8_unicode_ci;
 
python/django.txt · Last modified: 2015/01/28 13:12 by vondra