Skip to content

Commit

Permalink
Merged pullrequests found in jacobian's repo, jacobian#71,jacobian#74,j…
Browse files Browse the repository at this point in the history
…acobian#75

+ fix the field name restrictions layout
+ import error - "from mysite. books.models import Book" to "from books.models import Book" jacobian#75,jacobian#74
+ The settings.py file has been purposefully simplified in recent versions of Django, So TEMPLATE_DIRS dictionary is now removed from settings.py
  • Loading branch information
suhailvs committed Jun 16, 2014
1 parent 9ddabfb commit ed7d74d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
35 changes: 14 additions & 21 deletions chapter04.rst
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion chapter05.rst
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion chapter06.rst
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions chapter10.rst
Expand Up @@ -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
-----------------------------

Expand Down

0 comments on commit ed7d74d

Please sign in to comment.