开发者

Practical Django Projects - Pages 71 and 80

I am reading the book "Practical Django Projects". It is a nice book. I have a few questions though :

On page开发者_开发技巧 71, there is the following code :

from django.conf.urls.defaults import *
    from django.contrib import admin
admin.autodiscover()

from coltrane.models import Entry

entry_info_dict = {
    'queryset': Entry.objects.all(),
    'date_field': 'pub_date',
}

...

However no variable 'pub_date' has yet been defined in that file !

On page 80, I am being told that I should place two variables DELICIOUS_USER and DELICIOUS_PASSWORD in the Django settings file. I should then call that file with

from django.conf import settings

Where is that Django settings file ? In C:\Python27\Lib\site-packages\django\conf ?


  1. pub_date refers to coltrane.models.Entry attribute pub_date see the source

  2. from django.conf import settings imports your project settings.py so you have to define your settings inside your project/settings.py file. Here are some docs on the official docs about using settings in python code


pub_date is referencing a field defined in the Entry model. Django will look up the field by name later, which is why it's in quotes (otherwise it would trigger an NameError).

In models.py, you should have something like:

class Entry(models.Model):
    ...
    pub_date = models.DateField(...)

The settings file is typically called settings.py, and is located in your project's root folder (next to manage.py, etc.).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜