Python Tutorial

Showing posts with label django. Show all posts
Showing posts with label django. Show all posts

Wednesday, November 20, 2013

Tastypie: Django REST API framework

Tastypie is an webservice API framework for Django. It provides a convenient, yet powerful and highly customizable, abstraction for creating REST-style interfaces.
http://django-tastypie.readthedocs.org/en/latest/

Tuesday, May 14, 2013

django celery : asynchronous task queue, scheduling

django-celery provides celery integration for django. Using django-celery we can maintain asynchronous task queue/job queue. It is focused on real-time operation, but supports scheduling as well.

Installation:
$ pip install django-celery

Tuesday, December 4, 2012

Django-piston REST API


REST API using django and django-piston.
Piston lets you develop API for your site. From my experience in piston you can write API very fast. Lets have a small drive ...
A sample API code with readme available on github.

Saturday, November 3, 2012

django hello world


Django is python high level framework. It always encourage rapid development and clean, pragmatic design. It lets you build high-performing, elegant web applications quickly. You can also develop back-end API(django have some cool library for it). Lets go....

Create a django project.

From command prompt:
Create django project: django-admin.py startproject django_hello_world
Create django app: python manage.py startapp hello

I am using pycharm, so I can create my project from pycharm.

Here I show you only which file I need to edit for run hello world project.
You can download full projcet from here

 

// settings.py

# set admin
ADMINS = (
    ('jony', 'jony.cse@gmail.com'),
)

#set database
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', 
        # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'dev.db',                      
        # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      
         # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      
        # Set to empty string for default. Not used with sqlite3.
    }
}
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'hello', # need to install your app
)

//views.py

# create a view function which we will call
from django.http import HttpResponse
def hello_view(request):
    return HttpResponse("Hello my django!!")
	
//url.py

#call view from url
from hello import views
urlpatterns = patterns('',
    url(r'^hello_django/$', views.hello_view, name='my_hello_view'),
)




running project:

commands:
python manage.py syncbd 
# when you make chage on db, need to run this command
# create super user
python manage.py runserver 8080

Not hit this url:
http://127.0.0.1:8080/hello_django/

django install


Install from pip:
pip install Django

or
download django package and install by command python manage.py install