Django app

From Finninday
Jump to: navigation, search

Notes while running through the Django tutorial

First, browse the overview here: https://docs.djangoproject.com/en/1.6/intro/overview/

The real tutorial is here: https://docs.djangoproject.com/en/1.6/intro/tutorial01/

Oops, have to install (https://docs.djangoproject.com/en/1.6/intro/install/) before doing the tutorial.

Ahh, I guess it *is* installed:

rday@weasel:~/bin$ dpkg -l "*django*"
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                        Version            Architecture       Description
+++-===========================-==================-==================-============================================================
ii  python-django               1.6.1-2ubuntu0.2   all                High-level Python web development framework
un  python-django-doc           <none>             <none>             (no description available)
ii  python-django-tagging       1:0.3.1-3          all                Generic tagging application for Django projects

rday@weasel:~/bin$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
1.6.1

OK, back to the tutorial.

rday@weasel:~/church-django$ django-admin.py startproject mysite
rday@weasel:~/church-django$ tree
.
└── mysite
    ├── manage.py
    └── mysite
        ├── __init__.py
        ├── settings.py
        ├── urls.py
        └── wsgi.py

2 directories, 5 files

sidebar to set up git repo for the code

Tried running the development server on weasel, but ran into firewall rules. Moved development to a workstation which is more in the spirit of the tutorial.

Had to install django there...

root@ferret:~/git/church-django/mysite# apt-get install python-django

And get the codebase

rday@ferret:~/git$ git clone ssh://weasel/drobo2/git/church-django.git
Cloning into 'church-django'...

install python mysql connector

root@ferret:~/git/church-django/mysite/mysite# dpkg -l python-mysqldb
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                        Version            Architecture       Description
+++-===========================-==================-==================-============================================================
ii  python-mysqldb              1.2.3-2ubuntu1     amd64              Python interface to MySQL

set up mysql database

mysql> create database django character set utf8;
Query OK, 1 row affected (0.04 sec)

create db user

mysql> create user church_django identified by 'somepassword';
Query OK, 0 rows affected (0.12 sec)

mysql> grant all on django.* to 'church_django'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.08 sec)
  • test connection
rday@ferret:~/git/church-django/mysite$ mysql -u church_django -h 10.0.0.3 -p django
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 75124
Server version: 5.5.37-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| django             |
| test               |
+--------------------+
3 rows in set (0.00 sec)
rday@ferret:~/git/church-django/mysite$ python manage.py syncdb
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'rday'): 
Email address: rday@finninday.net
Password: 
Password (again): 
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

create app tables

  • edit the models
  • sync the db
rday@ferret:~/git/church-django/mysite$ python manage.py syncdb
Creating tables ...
Creating table polls_poll
Creating table polls_choice
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)


part two of tutorial

https://docs.djangoproject.com/en/1.6/intro/tutorial02/