Friday, August 2, 2013
Thursday, July 25, 2013
Using Django Default Authentication
Documentation page that explains how to use the Django default authentication:
https://docs.djangoproject. com/en/1.5/topics/auth/ default/#topic-authorization
https://docs.djangoproject.
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, July 3, 2013
Simple Web Server with Python
Use: python -m SimpleHTTPServer 8080
Ref: http://www.linuxjournal.com/content/tech-tip-really-simple-http-server-python
Monday, July 1, 2013
Wednesday, June 26, 2013
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"'
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
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
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
Subscribe to:
Posts (Atom)
