From ed7d74d1de25d70312e1e691aab9113aac961fe5 Mon Sep 17 00:00:00 2001 From: suhailvs Date: Mon, 16 Jun 2014 06:58:46 +0530 Subject: [PATCH] Merged pullrequests found in jacobian's repo, #71,#74,#75 + fix the field name restrictions layout + import error - "from mysite. books.models import Book" to "from books.models import Book" #75,#74 + The settings.py file has been purposefully simplified in recent versions of Django, So TEMPLATE_DIRS dictionary is now removed from settings.py --- chapter04.rst | 35 ++++++++++++++--------------------- chapter05.rst | 2 +- chapter06.rst | 2 +- chapter10.rst | 6 ++++-- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/chapter04.rst b/chapter04.rst index 713be56..44edb69 100644 --- a/chapter04.rst +++ b/chapter04.rst @@ -1098,32 +1098,25 @@ To solve these issues, we'll use *template loading* and *template directories*. Template Loading ================ -Django provides a convenient and powerful API for loading templates from the -filesystem, with the goal of removing redundancy both in your template-loading -calls and in your templates themselves. +Django searches for template directories in a number of places, depending +on your template-loader settings (see `Loader types` below), but the most +basic way of specifying template directories is by using the TEMPLATE_DIRS +setting. -In order to use this template-loading API, first you'll need to tell the -framework where you store your templates. The place to do this is in your -settings file -- the ``settings.py`` file that we mentioned last chapter, when -we introduced the ``ROOT_URLCONF`` setting. - -If you're following along, open your ``settings.py`` and find the -``TEMPLATE_DIRS`` setting. By default, it's an empty tuple, likely containing -some auto-generated comments:: - - TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. - ) +The TEMPLATE_DIRS setting +------------------------- -This setting tells Django's template-loading mechanism where to look for -templates. Pick a directory where you'd like to store your templates and add it -to ``TEMPLATE_DIRS``, like so:: +Tell Django what your template directories are by using the TEMPLATE_DIRS setting +in your settings.py file. This should be set to a list or tuple of strings that +contain full paths to your template directory(ies). Example:: TEMPLATE_DIRS = ( - '/home/django/mysite/templates', + "/home/html/templates/lawrence.com", + "/home/html/templates/default", ) +Your templates can go anywhere you want, as long as the directories and templates +are readable by the Web server. They can have any extension you want, such as +.html or .txt, or they can have no extension at all. There are a few things to note: diff --git a/chapter05.rst b/chapter05.rst index 4d8200d..837a74e 100644 --- a/chapter05.rst +++ b/chapter05.rst @@ -78,7 +78,7 @@ Here's a sneak preview of how the previous view can be rewritten using Django's database API:: from django.shortcuts import render - from mysite.books.models import Book + from books.models import Book def book_list(request): books = Book.objects.order_by('name') diff --git a/chapter06.rst b/chapter06.rst index 7af142f..a523c41 100644 --- a/chapter06.rst +++ b/chapter06.rst @@ -240,7 +240,7 @@ Within the ``books`` directory (``mysite/books``), create a file called ``admin.py``, and type in the following lines of code:: from django.contrib import admin - from mysite.books.models import Publisher, Author, Book + from books.models import Publisher, Author, Book admin.site.register(Publisher) admin.site.register(Author) diff --git a/chapter10.rst b/chapter10.rst index a639051..be7bb98 100644 --- a/chapter10.rst +++ b/chapter10.rst @@ -88,11 +88,13 @@ model name to ``_set``. .. admonition:: Field name restrictions - A field name cannot contain more than one underscore in a row, due to the way Django’s query lookup syntax works. For example: + + A field name cannot contain more than one underscore in a row, due to the way + Django’s query lookup syntax works. For example:: class Example(models.Model): foo__bar = models.IntegerField() # 'foo__bar' has two underscores! - + Accessing Many-to-Many Values -----------------------------