Sunday, December 15, 2013

Django Logging Tutorial
1.Update LOGGING section in settings.py with logger,handler,formatter fields
  Logger which specifies the handler, in this case it is file
 'loggers': {
        'logapp':{
            'handlers': ['file'],
            'level': 'DEBUG',
        },
    }
  File handler specifies the filename "logapp.log", also specifies theformatter in this case it is simple.
  'handlers': {
        'file':{
            'level':'DEBUG',
            'class':'logging.FileHandler',
            'filename':'logapp.log',
            'formatter':'simple'
        },
    }
  Formatter specifies the formatter in this case it is 'simple'.
 'formatters':{
        'simple':{
           'format':'%(levelname)s %(message)s'
        }
    },
2. import logging modules and add the logger message lines whereever it is required to have log message.

    logger.debug("This is debug message")
    logger.error("This is error message")

3. log messages will be printed in the log file in this case "logapp.log"
   http://127.0.0.1:8000/logproject/

4.Source Code can be downloaded from the github
https://github.com/Jadatravu/Tutorials/tree/master/django_tutorials/logproject

Note: This tutorial is compatible with django 1.5.4, python 2.7.4

Tuesday, December 3, 2013

Django Helloworld tutorial
1. Install django from pip or apt-get/yum 2. Install mysql, python-mysqldb pacakge from apt-get/yum 3. Create database in mysql using steps mentioned in the url creating-database 4. Creating mysql user and granting database permissions to the created user using the steps mentioned in the url adding-users 5. Edit helloworld/settings.py for database settings [ Database(mysql), Database name, Database user, Database user password] 6. Run server in the helloworld directory python manage.py runserver
7. Open the url http:/127.0.0.1:8000/helloworld


8.Source Code can be downloaded from the github
https://github.com/Jadatravu/Tutorials/tree/master/django_tutorials/helloworld
Note: This tutorial is compatible with django 1.5.4, python 2.7.4