目前在学The Django Book,发现书中有些东西跟现实(我的Django版本是1.5)不符,从第七章开始,不知道以后还会不会有错误,反正暂且先记下来


第七章:(form)

A simple form handling example:

对url映射 urls.py的修改,原文为:

from mysite.books import views
urlpatterns = patterns('',
    # ...
    url(r'^search-form/$', views.search_form),
    # ...
)

第一行应改为:

from books import views


添加search view时,原文为:

from django.http import HttpResponse
from django.shortcuts import render_to_response
from mysite.books.models import Book
def search(request):
    if 'q' in request.GET and request.GET['q']:
        q = request.GET['q']
        books = Book.objects.filter(title__icontains=q)
        return render_to_response('search_results.html',
            {'books': books, 'query': q})
    else:
        return HttpResponse('Please submit a search term.')

第3行应改为:

from books.models import Book