当我尝试从 Django 框架运行我的程序并在 Cassandra 数据库中插入一条记录时,错误提示:错误请求:未知标识符 id 我该怎么办?这是错误:
CQLEngineException at /registered/
Bad Request: Unknown identifier id
Request Method: GET
Request URL: http://127.0.0.1:8000/registered/?txtID=3&txtName=3&txtUsername=3&txtPassword=3
Django Version: 1.5.1
Exception Type: CQLEngineException
Exception Value:
Bad Request: Unknown identifier id
Exception Location: C:\Python27\lib\site-packages\cqlengine\connection.py in execute, line 221
Python Executable: C:\Python27\python.exe
Python Version: 2.7.4
Python Path:
['D:\\Developer Center\\PyCharm\\Bookstore',
'C:\\Python27\\lib\\site-packages\\pip-1.3.1-py2.7.egg',
'C:\\Python27\\lib\\site-packages\\mysql_python-1.2.4-py2.7-win32.egg',
'D:\\Developer Center\\PyCharm\\Bookstore',
'C:\\Windows\\SYSTEM32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages',
'C:\\Python27\\lib\\site-packages\\PIL']
Server time: Sat, 11 Jan 2014 16:48:09 +0330
Traceback Switch to copy-and-paste view
C:\Python27\lib\site-packages\django\core\handlers\base.py in get_response
response = callback(request, *callback_args, **callback_kwargs)
...
▶ Local vars
D:\Developer Center\PyCharm\Bookstore\BookstoreApp\views.py in register_user
User.create(id=str(id),name=name,username=username,password=password)
...
▶ Local vars
C:\Python27\lib\site-packages\cqlengine\models.py in create
return cls.objects.create(**kwargs)
...
▶ Local vars
C:\Python27\lib\site-packages\cqlengine\query.py in create
return self.model(**kwargs).batch(self._batch).save()
...
▶ Local vars
C:\Python27\lib\site-packages\cqlengine\models.py in save
self.__dmlquery__(self.__class__, self, batch=self._batch).save()
...
▶ Local vars
C:\Python27\lib\site-packages\cqlengine\query.py in save
execute(qs, query_values)
...
▶ Local vars
C:\Python27\lib\site-packages\cqlengine\connection.py in execute
return connection_pool.execute(query, params)
...
▶ Local vars
C:\Python27\lib\site-packages\cqlengine\connection.py in execute
raise CQLEngineException(unicode(ex))
...
▶ Local vars
模型:
class User(Model):
id = columns.Text(primary_key=True)
name = columns.Text()
username = columns.Text()
password = columns.Text()
意见:
def register_form(request):
return render_to_response('registration.html')
def register_user(request):
connection.setup(['127.0.0.1:9160'])
sync_table(User)
id = request.GET['txtID']
name = request.GET['txtName']
username = request.GET['txtUsername']
password = request.GET['txtPassword']
User.create(id=str(id),name=name,username=username,password=password)
return render_to_response('OK')
register_user 处理从registration.html收到的信息
注册.html
<!DOCTYPE html>
<html>
<head>
<title>Registration</title>
</head>
<body>
<form action="/registered/" method="get">
<ul>
<li>
<label>ID</label>
<input ty="text" name="txtID">
</li>
<li>
<label>Username</label>
<input ty="text" name="txtName">
</li>
<li>
<label>Username</label>
<input ty="text" name="txtUsername">
</li>
<li>
<label>Password</label>
<input ty="text" name="txtPassword">
</li>
<li>
<label></label>
<input type="submit" value="Register">
</li>
</ul>
</form>
</body>
</html>