Monday, December 19, 2016

Django


  • version
    • python 
Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2Type "help", "copyright", "credits" or "license" for more information.
> import django
> django.VERSION
(1, 8, 0, 'final', 0)
  • create a new site
    • “django-admin.py startproject mysite”   creates a mysite directory in your current directory.
  • templates
    • Django template language uses  {% %} in the html
    • {% if results %}
  • logs

    •     logger = logging.getLogger('my-django-logs')
    •     logger.info('________________________ (3)')
    • LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' }, 'applogfile': { 'level':'DEBUG', 'class':'logging.handlers.RotatingFileHandler', 'filename': os.path.join('/tmp', 'my-django-logs.log'), 'maxBytes': 1024*1024*15, # 15MB 'backupCount': 10, } }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, 'my-django-logs': { 'handlers': ['applogfile'], 'level': 'DEBUG', } } }
  • clearsessions
    • python ./manage.py clearsessions (cleans up django_session in MySQL)

No comments: