Index

imageSYMBOLS

# (pound sign) for Python comments, 13

% extends % tag, 99

?P construct, 66

__import__() function, 117

__init__.py file, 7, 27

__unicode_ () method, 34, 62, 198

_default_manager, 120

+= (plus equal) in Link model, 85

% for % loop, 108109

% free_comment_form % tag, 126

% if_bookmarked % template tag, 191192

% load % tag, 128

% url % template tag, 102, 232

500 Internal Server Error, 78

imageA

abstract inheritance, 124

activate script, 211

add() function, arguments for, 79

add_snippet view, 178179, 184

admin application

adding new flat page to, 1516

templates and, 2425

admin documentation system, 22

admin form

for adding a category, 51

for search keywords, 36

admin interface, adding categories to, 51

admin/ URL pattern, 13

admin/change_form.html template, 25

admin/flatpages/change_form.html template, 25

admin/flatpages/flatpage/change_form.html template, 25

administrative interface

home page, 13

templates/ directory use by, 19

admin.py files, 156

ADMINS setting, 136

aggregate method, 199

aggregate queries, 160

Akismet API key, 131

Akismet class

importing, 132

methods in, 132

annotate method, 161

APIs, Django, 233

applications

building for flexibility, 228

developing multiple, 226228

vs. projects in Django, 4445

reasons to make separate, 228

recognizing need to spin off new, 227

techniques for developing reusable, 224

tightly focused, 225

unit-testing, 219221

archive_day, 71

archive_index, 71

archive_month, 71

archive_year, 71

arguments, supplying default value for new, 230

as_li() method, 183

as_p() method, 182

as_table() method, 182183

as_ul() method, 182

associative arrays, 27

Atom feeds, 140141, 147

AUTHORS/AUTHORS.txt file, 237

imageB

base_entries.html template, 103

base_links.html template, 104

base_tags.html template, 104

BaseCommentAbstractModel, 123

base.html template, 98

bisecting feature (VCS), 221

Bitbucket, 208

blank fields vs. null fields, 54

block.super variable, 99

blog

adding block in body tag, 102

blog_url keyword argument, 132

filling in header for, 101

sidebar block, 109

Bookmark model

querying for user's bookmarks, 188

running queries on, 188

bookmark_set attribute, 188

bookmarking

basic bookmark views, 188

deleting bookmarks, 189

snippets, 187188

BooleanField, 56

braces, using in template tags, 126

brochureware sites, 9

build tools, 212214

bytecode, Python storage of, 8

imageC

cab application, 149150

cab/models.py, 187

cab/snippet_form.html template, 184

cab/templatetags/snippets.py, 192

cab/urls/popular.py, 163

cab/urls/snippets.py

adding new URL pattern to, 182

changing import line in, 184

cab/views file, 188189

cab/views/popular.py, 163

cab/views/snippets.py file

adding imports for editing snippets, 183

finished, 185

categories

Category model, 95

Category object, 85

CategoryAdmin class, 50

considerations for showing, 108

looping over, 108

setting up views for, 8485

categorization for Link model, 77

categorized feeds

adding items to import statements, 144

problems associated with, 144

writing feed class for, 144

change_form.html template, 25

CHANGELOG/CHANGELOG.txt files, 237

CharField, 57

choices option, 57

clean() method, 171

clean() validation method, 168

clean_username() method, 167

cleaned_data dictionary, 171

CMS project

choosing template directory for, 1920

customizing simple, 23

putting together, 1218

cms subdirectory, creating, 6

code

coupled to projects, 234

form for adding snippets, 174176

version control systems to track, 205209

coltrane directory, 6566

coltrane_tags.py file, 114

coltrane/entry_archive_year.html template, 105

coltrane/entry_archive.html template, 104

coltrane/entry_detail.html template

adding comment form header to, 125

creating, 68

editing, 99

coltrane/link_detail.html template, 99, 111

commas, trailing, 20

Comment model, 123

comment moderator, 130

comment_check() method, 133

in akismet module, 132

arguments expected by, 132

commenting, 123

comment-moderation function, 134

comment-moderation system, features of, 138140

CommentModerator class, 233

comments

allowing and disallowing, 56

application (Django), 124125

comments tag library, 125

comment-submission system, 129

e-mail notification of, 135

moderating, 129

Python, 13

retrieving and displaying, 127

commit=False on forms, 182

compilation function

changing to retrieve model class, 118

error checking, 119

problems with changing, 118

writing for % if_bookmarked % tag, 193

concrete inheritance, 124

connect method, 130

contact_form view

argument, rewriting, 232

effect of passing right arguments to, 231232

contact-form application

building for flexibility, 228229

flexible post-form processing, 231232

simple view for processing, 229

Context class, 27

context processor function, 111, 196

conversion programs, HTML, 60

count() method (QuerySet), 40

create() method, 176

create_user() method, 169

cross-site request forgery (CSRF), 189190

custom tags

creating simple, 113

registering new, 114

writing compilation function for, 113

imageD

databases

DATABASE settings, 910, 217

using different, 10

date filter for weblog application, 66

date-based archives, 70

date-based constraints supported by Django, 55

datetime class, 53

datetime module, 154

DateTimeField, 53

.db file extension, 10

DEBUG setting (Django), 218219

decorators, 74

def keyword, 28

default.html file, 20

del.icio.us, 77

Delicious, 7778

deployment tools, 214215

development process, Django

relative paths in settings, 217218

settings changing with environments, 218219

unit-testing applications, 219221

without projects, 215216

distinct() method, 38

distributing Django applications, 234

distutils module

for distributing Django applications, 234

writing setup.py script with, 235236

div tags (elements), 100101

Django

accessing settings file, 80

APIs, 233

building first site, 9

built-in management script, 6

contrib applications in, 12

database lookup syntax, 29

default site object created by, 15

development of, 2

DJANGO_SETTINGS_MODULE environment variable, 215216

django-admin.py, 9, 150, 216

django.contrib, 123

django.contrib.admin application, 12

django.contrib.auth, 11, 56

django.contrib.comments, 123, 126, 127

django.contrib.comments.moderation. CommentModerator, 138

django.contrib.flatpages application, 12

django.contrib.sites, 11, 15

django.contrib.syndication application, 123

django.contrib.syndication.feeds.Feed class, 141

django.core.mail, 137

django.core.urlresolvers.reverse() function, 232

django.db.models.Count, 160

django.db.models.get_model() function, 117

django.db.models.permalink(), 232

django.db.models.Sum filter, 198

django.shortcuts.render_to_response function, 31

django-tagging application, 59

django.template module, 18

django.template.Context class, 196

django.template.loader.select_template, 25

django.template.Node, 114

django.template.Template class, 112

django.utils.encoding.smart_str() function, 80, 133

django.views.generic.date_based module, 70

django.views.generic.list_detail module, 86

documentation displayed within, 238239

flat page example, 20

handling of database queries, 94

installing, 45

introduction to, 5

looking ahead, 8

packaged releases vs. development code, 4

process for loading templates, 112

server error page, 17

setting up database in, 8, 11

use of customized extensions to reST syntax, 240

Django applications

distributing, 234

what to document in, 239

writing, 44

Django project

changing address and port, 6

configuring cms, 912

creating, 5

exploring, 8

Django templates

for categories, 109

parsing ahead in, 192

workings of, 112

docstrings, Python, 238240

documentation

for distributable applications, 237

links, 22

imageE

editing

edit_snippet view, 197

snippets, 183186

e-mail

sending from within Django, 136

verifying settings for, 136

entries

adding list of latest, 115

categorizing and tagging, 58

entries.py file, breaking down, 91

entry detail, 107

entry index, 104, 105

Entry model class, 6162, 130

entry templates, 72

entry_detail template, 97

entry_detail view, 67

entry_detail.html template, 127128

entry_info_dict variable, 69

Entry.HIDDEN_STATUS, 58

Entry.LIVE_STATUS, 58

Entry.objects.all(), 70

querying with status field set to Live, 93

types of, 57

writing without HTML, 60

error checking, 117

excerpt field, 54

imageF

Fabric software, 214, 215

feature creep, 224

featured entries, 5556

feed class example, 142

feed GUID, 142

feeds

adding to weblog application, 140

categorized, 144147

directory, creating files in, 143

feeds.py file, 145, 147

fields

classes in django.newforms module, 165

core needed for Link model, 7778

in Django, 29, 34

filter() method

in QuerySet, 40

using for entries, 93

:filter shortcut, 241

fixtures (files), 221

FlatPage class, 2728

FlatPage object, 21

flatpages/default.html template, 30

flatpage.title variable, 21

Foord, Michael, 132

ForeignKey field, 55

for/endfor tags, 30

Form class

adding fields to, 175

in django.newforms module, 165

forms

for adding code snippets, 174

adding custom _init_() method to, 174

fields, requirement for, 168

form and /form tags, 182

form-handling code in django.newforms module, 165

forms.py, 175

generating from model definition, 179182

processing in code-sharing application, 165

rendering into different types of HTML, 182

simplifying templates that display, 182183

validation, 170172

full_clean() method, 171

functions vs. return values, 55

imageG

generic relations, 59, 60

generic views, 8687, 230

get_absolute_url() method

adding to admin interface, 62

adding to model, 52

defining, 151

on Entry model, 66

rewriting on Entry model, 74

get_comment_list tag, 137

get_content_object() method, 131

get_model() method, 117118

get_object() method, 144

get_object_or_404() function, 68

get_template function, 2930

GitHub, 208

Google Project Hosting, 208

GUIDs (globally unique identifiers), 141142

imageH

hash tables, 27

help_text

adding to admin interface fields, 62

argument, adding to field in model, 51

hidden option, 58

highlighted code, styling, 158

History button on flat page, 16

hosting options (VCS), 208

HTML, adding fields for storing, 60

HTTP (HyperText Transfer Protocol)

headers, 134

HttpResponse class, 27

HttpResponseForbidden class, 183

imageI

idempotent HTTP methods, 190

if tags, 33, 66

IfRatedNode, 200

import statement, changing for Rating model, 200

include() directives, 90

include() function, 72

index page, items listed on, 15

inheritance

abstract, 124

concrete, 124

template, 9899

input type=, 166, 182

INSTALL or INSTALL.txt file, 237

INSTALLED_APPS setting

adding applications to, 1213

adding coltrane application to, 48

changing, 11

instance argument, 131

IntegerField, 57

is_public field, 131

item_pubdate() method, 141

items() method

adding to the feed class, 141

changing for categorized feeds, 145

imageJ

jscripts/ directory, 23

imageK

keyword arguments

in Python, 68

unique constraint generated by, 78

keywords

improving CMS search function with, 33

keyword field in Django data model, 34

keyword_results[0].get_absolute_url() method, 40

imageL

Language model, 151, 176

LatestContentNode, writing, 119120

LatestEntriesFeed, setting up, 140

lexers in pygments download, 151

libraries, Django, 23

LICENSE/LICENSE.txt file, 236

linebreaks filter, 127

Link class, 7781

Link model

adding customized save() method to, 79

adding foreign key to, 78

adding more patterns to, 88

basic core fields for, 77

defining dictionary for generic views, 83

full model definition, 81

installing database table for, 81

link_detail template, 98

link-aggregation service, 78

links.py file, 9192

template used for generic view, 97

using _unicode_() method with, 79

writing, 7783

Live entries, 9395

loader module, 27

login_required decorator, 177178

login/logout views, 178

imageM

magic numbers, 58

mail_managers() function, 136137

manage.py file, 7

manage.py script, 6, 216

manage.py startapp command, 45

manage.py syncdb

database tables created by, 13

installing Category model table with, 48

running, 12

running to install model into database, 188

managers

in Django model system, 94

Manager, writing subclass of, 94

MANAGERS setting, 136

managers.py file, 161

many-to-many relationships

commit=False and, 182

how they work, 59

ManyToManyField, 5859

markdown filter, 127

media files, 24

Mercurial software, 208, 214

Mercurial: The Definitive Guide, 209

Meta class, 50

metadata, 78

mod_wsgi module, 211

ModelForm class

adding URL pattern for, 184

customization supported by, 180

telling to edit existing object, 184

using, 180

models

designing for weblog application, 4752

model classes, 6263

model definitions, 179182

ModelChoiceField, 175

ModelForm helper, 233

retrieving content from, 117119

models.py file

adding category to, 50

creating Django data model in, 3334

partial for weblog application, 63

moderate_comment function, 134

moderation rules, setting up, 233

moderation system for screening incoming comments, 129

monthly archive template, 107

monthly/daily archives, 106

multiple applications, developing, 226228

MyModel.object_fetcher.all() method, 94

imageN

naming style in Python, 28

newforms package, 186

NodeList, 194

null fields vs. blank fields, 54

imageO

object_detail generic view, 86, 97

object_detail view, 72

object_list generic view, 86, 158

object-relational mapper (ORM), 22

objects attribute (django.db.models.Manager class), 94

ORDER BY title ASC, 52

order of URL patterns, 17

order_by method, 161

orthogonality, 227228

os.path module (Python), 217

imageP

?P construct, 66

packaging tools, Python, 234235

page field (Django data model), 34

Page not found error, 17

page/paginator variables (Snippet model), 158

parser argument, 193

passwords

PasswordInput widget, 167

validating, 168

patterns() function, 85

permalink decorator, 74, 81

permission errors, 6

pip software, 212, 214

placeholders, writing templates with, 98

plain attributes vs. methods of feeds, 145

post_save signal, 130

pre_save signal, 131

prepopulated_fields argument, 50

preview.html template, 126

primary keys, 35

projects

vs. applications in Django, 4445

creating Django, 5

pub_date field

adding default ordering for, 79

providing default value for, 55

showing for blog, 107

py_modules argument, 236

.pyc extension, 8

pydelicious module, 79

pygments

highlight function, 154

pygments.lexers.get_lexer_by_name() method, 152

Python library, 150

syntax highlighting, 158159

Python

admonition about learning, 3

decorator syntax, 75

importance of reading tutorial, 9

interactive interpreter, 3

introduction to, 34

isolated environments for software management, 209, 211

Markdown module, importing, 154

naming applications, 45

naming style, 28

python setup.py install, 236

python setup.py sdist, 236

regular-expression syntax, 6667

stopping the server, 7

understanding function arguments, 68

Python modules

giving docstrings to, 238

installing third-party, 79

Python package

Index, 150

packaging tools, 234235

standard files to include in, 236237

Python path

changing, 46

putting code in directory on, 46

imageQ

q variable, 32

queries

aggregate, 160

execution (Django), 40

QuerySet

class (Django), 40

object, methods in, 233

queryset argument, 70

queryset_or_model argument, 88

imageR

Rating model/object, 199

README/README.txt file (Python), 236

recursive-include statements, 237

regular expressions, 14

Reinhardt, Django, 2

related_name argument, 188

relative paths in settings, 217218

render() method, 113, 194195

render_to_response function, 31

reproducible builds, 212

RequestContext

vs. Context, 196

importing, 196

populating template variables with, 197

for template rendering, 232

using repetitively, 197

writing shortcut for, 197

request.GET.get(‘q’, ‘’) method, 32

resolve() method, 194

reStructuredText (reST)

learning, 240

syntax, 240

return values vs. functions, 55

rich-text editors (RTEs), 2326

imageS

safe HTTP methods, 190

SalesInquiryForm example, 230

save() method

adding code for Link model to, 8081

creating a User object with, 169

in Model class, 61

reason not to highlight in, 154

saving new User object with, 169

writing for Snippet model, 154155

scope creep, 224

search/ directory, 27

search keywords, 36, 45

search systems

adding to CMS project, 26

writing search view for, 27

search view

adding HttpResponseRedirect to, 3940

adding keyword_results to, 3839

adding keywords support in, 38

improving in CMS project, 3133

rewriting to display empty search form, 32

working without adding to INSTALLED_APPS, 35

security considerations in web applications, 33

SELECT COUNT method (QuerySet), 40

self.id, checking for, 81

self.post_elsewhere+, 81

send method, 130

server error page (Django), 17

settings

changing with environments, 218219

file, accessing (Django), 80

relative paths in, 217, 218

settings.py file, 8

setup.py script

for continuous packaging, 235

to generate distribution package, 235

writing with distutils, 235236

setuptools system (Python packages), 235

sidebars

adding explanations in, 102

adding lines to, 128

for blogs, 101102

rewriting in base.html template, 121

signals

class, 130

and Django dispatcher, 129130

Signup form, 170

signup.html template, 173

Site object, 132

site-packages directories, 46

slug fields

changing definition of, 50

field type, 47

slugs

adding to Link model, 78

and normalization, 50

Snippet model

adding custom manager to definition of, 162

building out basic fields, 153

extra variables for snippets, 157

fields in, 153

filling in author field, 174

finished, 155156

finished form for, 176

setting up templates for, 157

snippet_list template, 158

snippets

automatically generating form for adding, 182

bookmarking favorites, 187188

editing, 183186

and languages, 156

logical ordering for, 153

rating, 199

SnippetManager, 199

Snippets application

splitting up, 228

testing, 156

social code-sharing site

building in Django, 149

building initial models, 150

feature checklist, 149

setting up application, 150

software development

general rule for staying on track with, 224

importance of staying focused, 224225

scope creep in, 224

writing reusable applications in Django, 223

spam, filtering comments for, 129

split_contents method, 116

SQL injection attacks, 33

SQLite, 10

stack trace, 18

standalone and coupled applications, 45

startapp command, 2731

startproject command (django-admin.py), 7

statistical spam analysis, 131135

status fields, 58, 93

stop words in slug fields, 50

str() vs. smart_str() function (Django), 80

strings (Python)

formatting, 52

types of, 34

strptime function (Python), 67

style guide (Python), 62

Subversion, 208

success_url argument, 231

super() method

calling, 175

using, 61

syncdb command, 156

imageT

tagging application, 87

tagging.views.tagged_object_list view, 88

tags

adding to Link model, 78

applying to models, 59

entry detail template for, 110

extending template system with custom, 111

provided by Django template system, 19

registering and using new, 120122

tag() method, 114

Tag model, 87

:tag shortcut, 241

tag URI, 141142

TagField, importing into Snippet model, 153

tagging.views.tagged_object_list view, 88

tags.py file, 92

using new, 114115

views for, 8788

writing compilation function for, 116117

writing more flexible with arguments, 115116

templates

calling object's methods in, 30

chaining inherited, 100

choosing from multiple, 25

creating to generate HTML, 2930

defining base for blog, 100

for displaying entries, 104

displaying forms with, 182183

filters, applying, 60

flexible handling of, 230

how names are determined, 71

inheritance, 97100

for Link model generic views, 84

loaders, 19

for other types of content, 110

shortcut, 241

tagging.views.tagged_object_list view, 88

TEMPLATE_CONTEXT_PROCESSORS set, 196

TEMPLATE_DIRS, 19

template.Node, 193195

templates/ directory, 1920

TemplateSyntaxError, 193

templatetags directory, 192

templating system in Django, 1822

variables, 196

testing (unit-testing) applications, 27, 219, 221

TextFields, 47, 175

text-to-HTML converter

Markdown as, 61

save() method to apply, 78

third-party Python modules, installing, 79

TIME_ZONE setting, 11

timedelta class instance, 131

TinyMCE, 23

title elements, adding blocks for, 101

title templates, rendering for feed items, 143144

tools, VCS, 208

top authors, 160161

top_languages view, 162163

top_user view, rewriting, 162

tracking code with VCS, 205209

trailing commas, 20

trans tag, 127

truncatewords_html filter, 66

tuples

representing sequences of items with, 20

used by Python for version number, 5

imageU

uncommenting code, 13

unique_for_date constraint

supported by Django, 54

used on slug field, 68

unique_for_year constraint, 55

uniqueness constraints, 5455

unit-testing applications, 27, 219221

URL patterns

adding new to Link model, 8384

changing to specify different templates, 230231

order of, 17

replacing, 73

setting up for Rating model, 200

URLConf module

cleaning up, 93

making change to weblog, 74

provided by Django application, 44

pulling individual bits into, 93

in weblog application, 8890

URLs (Uniform Resource Locators)

configuration, 14

decoupling, 7275

directory, 157

flexible handling of, 232233

pattern naming, 152

setting up for adding and deleting bookmarks, 190

setting up for LatestEntriesFeed, 143

URLConf file (urls.py), 124

URLField (Link model), 7779

urls/snippets.py, 157

wiring up, 192

urls.py file

adding new line to, 2324

copying import statements and URL spatterns into, 7273

fixing, 17

rewriting to use generic views for entries, 70

setting up in cms directory, 66

users

creating new, 168

not specifying current as default, 56

and passwords, 169

rating system, 198202

signups, 165167

User model, importing into Snippet model, 153

User.DoesNotExist exception, 167

username field, validating, 167168

username/password in del.icio.us, 80

variable, 196

imageV

validation

custom for registration forms, 166

forms, displaying/processing, 172174

order of, 171172

ValidationError exception, 168

variables

provided by Django template system, 19

Variable class, 194

verbose_name options, 50

verify_key() method, 132

version control systems (VCS)

choosing/using, 208209

example, 206207

overview, 205206

tools and hosting options, 208

version control with Subversion, 209

view function, 28

View on Site button, 16

views

adding new arguments to (Django), 229230

adding top_languages to Snippet model, 163

creating file for rating snippets, 199200

disadvantages of changing handwritten, 196

generic (Django), 70, 233

handling project specific, 234

for HttpResponseForbidden class, 183184

improving of top authors, 161162

for languages, 159160

for listing current user bookmarks, 191

login/logout, 178

querying for most-bookmarked snippets, 191

setting up for categories, 8485

setting up for Snippet model, 158

specifying prefixes for, 73

starting with simple index, 65

for tags, 8788

using coltrane/category_detail, 85

using generic (Django), 69, 8687

views.py file, 27, 65

writing to process form, 177179

virtualenv tool, 210211

imageW

web applications, security and, 33

web development, 226228

web framework

definition and use of, 12

using Django as, 18

web pages, Django vs. hand-written, 19

web servers, launching to see administrative interface, 13

web sites, for downloading

Fabric software, 214

GitHub, 208

pip, 212

virtualenv tool, 210

zc.buildout, 212

web sites, for further information

Akismet web service, 129, 131

Apress Source Code/Download area, 163

content types framework documentation, 163

Django authentication system documentation, 178

Django database API documentation, 41, 94

Django installation instructions, 10

Django settings documentation, 10

django.contrib.syndication application, 141

django.newforms documentation, 186

django-tagging application, 59

docutils module, 240

for downloading Django, 4

for downloading Python, 3

Google Project Hosting, 208

IETF RFC 4151 standard, 141

Mercurial, 208

pydelicious, 79

pygments Python library, 150

Python documentation, 52

Python style guide online, 28

setuptools system information, 235

snippets application, 149

TinyMCE RTE, 23

weblog application

basic fields in, 5354

building model for entries, 52

creating standalone, 4547

creating templates for each view, 7172

creating urls directory in, 90

Django-powered, 43

expanding, 7795

feature checklist, 4344

finishing, 6162, 123

generic view tasks, 69

installing django.contrib.comments, 124125

new field types in, 47

section templates for, 103104

templates for, 97

viewing index of all entries created in, 66

writing Link model for, 6265

writing the first views for, 6569

widget classes (django.newforms module), 165

Windows, time zones in, 11

imageY

yearly archive, 105106

imageZ

zc.buildout software, 212

zoneinfo format, 11

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset