【发布时间】:2015-02-13 13:36:02
【问题描述】:
我正在使用 python 3.4、Django 1.7.1(书中考虑的版本)、Postgres 9.3,我的 IDE 是 Eclipse。
我一直在研究“轻量级 Django - Elman 和 Lavin”一书,在第 4 章和第 5 章中我被困了好几天,我们应该使用其余框架和骨干.js。举例来说,
Lightweight Django - Chapters 4 and 5
几天前,我尝试按照书中介绍的方式通过 myseld 进行编码,并检查了上面链接中提供的示例。但是,由于我没有继续,我决定复制上面链接中提供的代码并尝试运行。出现了同样的错误:
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 参数,或设置 read_only=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-framework。由于我使用的是上面链接中提供的确切代码,因此应该没有错误。实际上,只有一段代码我改变的是在settings.py中(错误反复发生后):
之前:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'scrum',
}
}
现在:
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
谁能帮我发现问题?
【问题讨论】:
标签: python django postgresql backbone.js django-rest-framework