我使用的是python 3.4、Django 1.7.1(本书考虑的版本)、Postgres 9.3,我的IDE是Eclipse.
我一直在学习《轻量级Django-Elman和Lavin》一书,我已经在第4章和第5章中呆了好几天,我们应该在这两章中使用rest框架和主干.js.比如说,
Lightweight Django - Chapters 4 and 5
几天前,我试着按照书中的介绍编写myseld的代码,并用上面链接中的示例进行判断.然而,由于我没有继续,我决定复制上面链接中的代码并try 运行.同样的错误也出现了:
AssertionError at /
Relational field must provide a `queryset` argument, or set read_only=`True`.
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.7.1
Exception Type: AssertionError
Exception Value:
关系字段必须提供queryset
个参数,或设置为只读=True
.
Exception Location: /usr/local/lib/python3.4/dist-packages/rest_framework/relations.py in __init__, line 35
Python Executable: /usr/bin/python3
Python Version: 3.4.0
Python Path:
['/home/daniel/workspace/Scrum',
'/usr/lib/python3.4',
'/usr/lib/python3.4/plat-i386-linux-gnu',
'/usr/lib/python3.4/lib-dynload',
'/usr/local/lib/python3.4/dist-packages',
'/usr/lib/python3/dist-packages']
这个错误出现在"relations.py"中,它属于django rest框架.由于我使用的是上面链接中给出的代码,所以应该没有错误.实际上,我唯一更改的代码是settings.py(错误反复发生后):
Before:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'scrum',
}
}
Now:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'scrum',
'USER': 'daniel',
'PASSWORD': '12345',
'HOST': '127.0.0.1',
'PORT': '5432',
}
如下所示,我的用户"daniel"具有以下属性:
Role name | Attributes | Member of | Description
-----------+------------------------------------------------+-----------+-------------
daniel | Superuser, Create DB | {} |
postgres | Superuser, Create role, Create DB, Replication | {} |
最后,我似乎对psycopg2的安装没有任何问题,因为我能够创建如下所示的"scrum".事实上,我的系统的数据库列表是
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
scrum | daniel | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/daniel +
| | | | | daniel=CTc/daniel
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
有人能帮我发现这个问题吗?