Tuesday, December 20, 2016

Python

>>> import form_utils
>>> form_utils.__file__
'/data1/django/lib/python2.6/site-packages/form_utils/__init__.pyc'
>>> globals()
{'__builtins__': , 'functools': , '__package__': None, '__name__': '__main__', 'os': , '__doc__': None}

print(globals())

find . -name \*.pyc -delete

------  python3
apt-get install python3

warning: don't change symbolic links in /usr/bin (/usr/bin/python and /usr/bin/python-config). Otherwise apt-get and other scripts don't work anymore.
Rather, add an alias in your .bashrc
alias python=python3

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)