Monday, July 8, 2013

Sign Up Example - angularJs - Simple Validation

This code uses a mix of AngularJs Validation and Javascript Validation, printing all error messages in the head of form:



Wednesday, June 26, 2013

Syntax highlighter for several languages in Python

http://pygments.org/

Serialization of datetime in python to json

>>> dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None
>>> json.dumps(datetime.datetime.now(), default=dthandler)
'"2010-04-20T20:08:21.634121"'

How to serve static files using Django (Use only in development!!)

Source: https://docs.djangoproject.com/en/1.2/howto/static-files/

Static pages, images and styles using Django

1. Step: Create the directory static inside of the application directory (<app_dir>/static)
    eg: mysite/polls/static

2. Step: Create one directory using the name of app inside of static directory (<app_dir>/static/<app_name> )
     eg:  mysite/polls/static/pools

3. Step: Put the content into the static directory

4. Step: Include  the command below into the HTML file
{% load staticfiles %}
e.g.:
{% load staticfiles %}

<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />



Tuesday, June 25, 2013

Django: How to activate the default administration site

See tutorial 2: https://docs.djangoproject.com/en/1.5/intro/tutorial02/

Django: How to setup views

See tutorial 3: https://docs.djangoproject.com/en/1.5/intro/tutorial03/

How create a new system using Django


1. Step: Verify if Django is installed:
python -c "import django; print(django.get_version())"

2. Step: Create a new project
django-admin.py startproject mysite
              ==> mysite is the name of project

Django: how to generate json response.

import json
def some_view(request):
    result = []
    result.append({"user":request.user})
    result
.append({"key":request.session.key})     return HttpResponse(json.dumps(result), mimetype='application/json')
Source: http://garmoncheg.blogspot.com/2011/06/django-how-to-generate-json-response.html

Basic Django Commands

Verify if django is intalled: python -c "import django; print(django.get_version())"

Run Django Shell: python manage.py shell

Create project: django-admin.py startproject <proj_name>  
    eg: django-admin.py startproject mysite

Create app:  python manage.py startapp <app_name>
    eg: python manage.py startapp polls
 
Sync database: python manage.py syncdb

Start Web Server (development): python manage.py runserver 8080

Run Unit Tests: python manage.py test <name>  
    eg: python manage.py test polls