>>>from django.utils.translation import ugettext_lazy as _

use

_

instead of

ugettext_lazy

—-

title = models.CharField(_(‘title’),max_length=250, help_text=’Maximum 250 characters.’)

__init__

is a constructor.

———

class FooBar:
def __init__(self):
self.somevar = 42
>>> f = FooBar()
>>> f.somevar
42

You can put initial value

class FooBar:
def __init__(self, value=42):
self.somevar = value

>>> f = FooBar(‘This is a constructor argument’)
>>> f.somevar
‘This is a constructor argument’

——

def

is to define function in Python.

—-

def  square(x):
return x*x

$

represents the end of string in regular expression.

r ‘ ‘

is the Python syntax for defining raw strings.

“from” loads a Python module into the current namespace, so that you can refer to it without the need to mention the module name again

>>>from django.conf.urls.defaults import *

A module is a file containing Python definitions and statements.

The file name is the module name with the suffix .py appended.

Within a module, the module’s name (as a string) is available as the value of the global variable __name__.

import loads a Python module into its own namespace

>>> import yourmodulename

© 2011 Web Oom Suffusion theme by Sayontan Sinha
Switch to our mobile site
Page 4 of 4«1234Top Footer