Showing posts with label debug. Show all posts
Showing posts with label debug. Show all posts

Thursday, 12 September 2013

Django - Site Matching Query Error

Site matching query does not exist. Lookup parameters were {'pk': 1}
Open Project Shell
python manage.py shell

Create Site Object
from django.contrib.sites.models import Site
Site.objects.create(pk=1, domain='example.com', name='example')
Best Practise
python manage.py syncdb --noinput
python manage.py migrate
python mange.py createsuperuser

Sunday, 8 September 2013

Python - Fix Non-ASCII Character in File

Encode in ANSI


Additional Headers (On Top of code)
#! /usr/bin/env python
# -*- coding: utf-8 -*-

EXTRA: For Windows (Optional)

Saturday, 1 June 2013

Python - snippetscream fix on Windows

snippetscream\_186.py
Replace
self.tmpfile = tempfile.NamedTemporaryFile()
To
self.tmpfile = tempfile.NamedTemporaryFile(delete=False)
# If delete is true (the default), the file is deleted as soon as it is closed. (New in version 2.6: The delete parameter.) [1]
Reference: http://docs.python.org/2/library/tempfile.html#tempfile.NamedTemporaryFile
Download: https://github.com/shaunsephton/django-snippetscream

Monday, 27 May 2013

Sunday, 26 May 2013

Django - External Debugger

Requirements (Choose one)
A. Install into site-packages
pip install django-debug-toolbar
pip install django-extensions
pip install Werkzeug

B. Download and put it all together into a directory
pip install --download="DEBUG" --no-install django-debug-toolbar django-extensions Werkzeug six
Reference: http://www.pip-installer.org/en/latest/cookbook.html
# After download then extract accordingly as following

Directory Tree
Projects
+---My_Project1
|   +---...
|
+---My_Project2
|   +---...
|
+---My_Project3
|   +---...
|
+---DEBUG
|   +---debug_toolbar
|   |   +---...
|
|   +---django_extensions
|   |   +---...
|
|   +---werkzeug
|   |   +---...
|
\---six.py
# I'm using method B.
local_settings.py
import os
import sys

from settings import MIDDLEWARE_CLASSES, INSTALLED_APPS

DEBUG_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../../DEBUG').replace('\\','/')
if os.path.exists(DEBUG_DIR):
     sys.path.append(DEBUG_DIR)
     MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
     INSTALLED_APPS += ('debug_toolbar', 'django_extensions',)
     INTERNAL_IPS = ('127.0.0.1',)
     DEBUG_TOOLBAR_CONFIG = {
       'INTERCEPT_REDIRECTS': False,
     }

Source Files:
https://github.com/django-debug-toolbar/django-debug-toolbar
https://github.com/django-extensions/django-extensions
https://github.com/mitsuhiko/werkzeug
https://pypi.python.org/pypi/six # For django-extensions