私はおそらく非常に基本的なものを欠いていますrequest['title']
が、関数で: を使用して投稿変数にアクセスしようとすると、次のエラーが発生します:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/ajax/drafts/create
Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'Knights',
'django.contrib.admin')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/auth/decorators.py" in _wrapped_view
20. return view_func(request, *args, **kwargs)
File "/Users/Mike/Desktop/Main/Django-Development/BBN/Knights/views.py" in document_create
179. title = request.POST['title']
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/utils/datastructures.py" in __getitem__
258. raise MultiValueDictKeyError("Key %r not found in %r" % (key, self))
Exception Type: MultiValueDictKeyError at /ajax/drafts/create
Exception Value: "Key 'title' not found in <QueryDict: {}>"
関数の完全なコードは次のとおりです。
def document_create(request):
user = request.user
title = request.POST['title']
if (title != ''):
Draft.objects.create(content='Your content goes here', user=user, title=title)
リストされている投稿変数は次のとおりです。
POST:
title = u'sdff'
編集: また、for ループでアイテムを一覧表示すると、タイトル変数が表示されます。