Your form is not a model form, and so you cannot pass instance=post. Since it is just a regular form, you should pass a dictionary of values, with the keys of the dictionary being the names of the fields.
If the form is representing a model, you should be using a model form. https://docs.djangoproject.com/en/1.3/topics/forms/modelforms/ Cheers Tom On Tue, Aug 16, 2011 at 4:47 PM, Phang Mulianto <braveh...@gmail.com> wrote: > > hi anyone can help me... > > On Mon, Aug 15, 2011 at 12:39 PM, Phang Mulianto <braveh...@gmail.com> wrote: >> >> Hi Daniel, >> >> i change it to instance, but still got other errors : >> >> def myadmin_change_post(request, >> template_name='blog/admin/change_post.html'): >> try: >> id= request.GET.get('id','4') >> except ValueError: >> id=1 >> #post = get_object_or_404(Post,pk=id) >> post = Post.objects.get(pk=id) >> form = AdminPostForm(instance=post) >> return render_to_response(template_name,locals(),context_instance = >> RequestContext(request) ) >> >> the form : >> >> class AdminPostForm(forms.Form): >> >> >> cat_choices = [('private','private')] >> >> title = >> forms.CharField(widget=forms.TextInput(attrs={'size':'20','value':'','class':''}),label='Title') >> content= >> forms.CharField(widget=forms.Textarea(attrs={'cols':'40','rows':'5'}),label='Content') >> slug = >> forms.CharField(widget=forms.TextInput(attrs={'size':'20','class':''}),label='Slug') >> is_publish = forms.BooleanField(label='Publish') >> categories = forms.ChoiceField(choices=cat_choices) >> created_at = >> forms.DateTimeField(widget=forms.DateTimeInput(),label='Created at') >> modified_at = >> forms.DateTimeField(widget=forms.DateTimeInput(),label='Modified at') >> >> any clue where the error migh be.. >> >> TypeError at /article/change/ >> >> __init__() got an unexpected keyword argument 'instance' >> >> Request Method: GET >> Request URL: http://127.0.0.1:8000/article/change/?id=2 >> Django Version: 1.3 >> Exception Type: TypeError >> Exception Value: >> >> __init__() got an unexpected keyword argument 'instance' >> >> Exception Location: >> C:\Users\mulianto\workspace\myblog\src\myblog\..\myblog\article\views.py in >> myadmin_change_post, line 132 >> Python Executable: c:\python27\python.exe >> Python Version: 2.7.2 >> Python Path: >> >> ['C:\\Users\\mulianto\\workspace\\myblog\\src\\myblog', >> 'c:\\python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg', >> 'c:\\python27\\lib\\site-packages\\simplejson-2.1.6-py2.7.egg', >> >> >> 'c:\\python27\\lib\\site-packages\\pyasn1-0.0.13-py2.7.egg', >> 'c:\\python27\\lib\\site-packages\\pymongo-1.11-py2.7-win32.egg', >> 'c:\\python27\\lib\\site-packages\\mongoengine-0.4-py2.7.egg', >> >> >> '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: Mon, 15 Aug 2011 12:32:23 +0800 >> >> Traceback Switch to copy-and-paste view >> >> c:\python27\lib\site-packages\django\core\handlers\base.py in get_response >> >> for middleware_method in self._view_middleware: >> >> response = middleware_method(request, callback, >> callback_args, callback_kwargs) >> >> if response: >> >> break >> >> if response is None: >> >> try: >> >> response = callback(request, *callback_args, >> **callback_kwargs) >> >> ... >> >> except Exception, e: >> >> # If the view raised an exception, run it through >> exception >> >> # middleware, and if the exception middleware >> returns a >> >> # response, use that. Otherwise, reraise the >> exception. >> >> for middleware_method in self._exception_middleware: >> >> response = middleware_method(request, e) >> >> ▶ Local vars >> Variable Value >> exceptions >> >> <module 'django.core.exceptions' from >> 'c:\python27\lib\site-packages\django\core\exceptions.pyc'> >> >> e >> >> TypeError("__init__() got an unexpected keyword argument 'instance'",) >> >> callback_args >> >> () >> >> receivers >> >> [(<function _rollback_on_exception at 0x025CFAB0>, None)] >> >> middleware_method >> >> <bound method CsrfViewMiddleware.process_view of >> <django.middleware.csrf.CsrfViewMiddleware object at 0x027A6C30>> >> >> self >> >> <django.core.handlers.wsgi.WSGIHandler object at 0x0276F4D0> >> >> settings >> >> <django.conf.LazySettings object at 0x01A788D0> >> >> request >> >> <WSGIRequest >> GET:<QueryDict: {u'id': [u'2']}>, >> POST:<QueryDict: {}>, >> COOKIES:{'csrftoken': '5fbc1b8cf0e31318c4f7a1904df1b5c2', >> 'sessionid': 'ee90c4ad05c1512cc424c7117f1320c9'}, >> META:{'ALLUSERSPROFILE': 'C:\\ProgramData', >> 'APACHE2TRIAD_DIR': 'd:\\apache2triad', >> 'APPDATA': 'C:\\Users\\mulianto\\AppData\\Roaming', >> 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files', >> 'COMPUTERNAME': 'MULIANTO-PC', >> 'COMSPEC': 'C:\\Windows\\system32\\cmd.exe', >> 'CONTENT_LENGTH': '', >> 'CONTENT_TYPE': 'text/plain', >> 'CSRF_COOKIE': '5fbc1b8cf0e31318c4f7a1904df1b5c2', >> 'DJANGO_SETTINGS_MODULE': 'myblog.settings', >> 'FP_NO_HOST_CHECK': 'NO', >> 'GATEWAY_INTERFACE': 'CGI/1.1', >> 'HOMEDRIVE': 'C:', >> 'HOMEPATH': '\\Users\\mulianto', >> 'HTTP_ACCEPT': >> 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', >> 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', >> 'HTTP_ACCEPT_ENCODING': 'gzip,deflate', >> 'HTTP_ACCEPT_LANGUAGE': 'en-us,en;q=0.5', >> 'HTTP_CONNECTION': 'keep-alive', >> 'HTTP_COOKIE': 'sessionid=ee90c4ad05c1512cc424c7117f1320c9; >> csrftoken=5fbc1b8cf0e31318c4f7a1904df1b5c2', >> 'HTTP_HOST': '127.0.0.1:8000', >> 'HTTP_KEEP_ALIVE': '115', >> 'HTTP_REFERER': 'http://127.0.0.1:8000/article/listall/', >> 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; >> rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18', >> 'LOCALAPPDATA': 'C:\\Users\\mulianto\\AppData\\Local', >> 'LOGONSERVER': '\\\\MULIANTO-PC', >> 'NUMBER_OF_PROCESSORS': '2', >> 'OPENSSL_CONF': 'd:\\apache2triad\\opssl\\bin', >> 'OS': 'Windows_NT', >> 'PATH': >> 'C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;;c:\\python27\\;;d:\\apache2triad\\bin;d:\\apache2triad\\perl\\bin;d:\\apache2triad\\php\\bin;d:\\apache2triad\\mysql\\bin;d:\\apache2triad\\opssl\\bin;d:\\apache2triad\\python\\bin;d:\\apache2triad\\pgsql\\bin;C:\\Program >> Files\\Enterprise Vault\\EVClient\\', >> 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC', >> 'PATH_INFO': u'/article/change/', >> 'PHP_PEAR_BIN_DIR': 'd:\\apache2triad\\php\\bin', >> 'PHP_PEAR_DATA_DIR': 'd:\\apache2triad\\php\\pear\\data', >> 'PHP_PEAR_DOC_DIR': 'd:\\apache2triad\\php\\pear\\docs', >> 'PHP_PEAR_INSTALL_DIR': 'd:\\apache2triad\\php\\pear', >> 'PHP_PEAR_PHP_BIN': 'd:\\apache2triad\\php\\bin\\php-cgi.exe', >> 'PHP_PEAR_SYSCONF_DIR': 'd:\\apache2triad\\php', >> 'PHP_PEAR_TEST_DIR': 'd:\\apache2triad\\php\\pear\\tests', >> 'PPM_DAT': 'd:\\apache2triad\\perl\\site\\lib\\', >> 'PROCESSOR_ARCHITECTURE': 'x86', >> 'PROCESSOR_IDENTIFIER': 'x86 Family 6 Model 23 Stepping 10, GenuineIntel', >> 'PROCESSOR_LEVEL': '6', >> 'PROCESSOR_REVISION': '170a', >> 'PROGRAMDATA': 'C:\\ProgramData', >> 'PROGRAMFILES': 'C:\\Program Files', >> 'PROMPT': '$P$G', >> 'PSMODULEPATH': 'C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\', >> 'PUBLIC': 'C:\\Users\\Public', >> 'QUERY_STRING': 'id=2', >> 'REMOTE_ADDR': '127.0.0.1', >> 'REMOTE_HOST': '', >> 'REQUEST_METHOD': 'GET', >> 'RUN_MAIN': 'true', >> 'SCRIPT_NAME': u'', >> 'SERVER_NAME': 'mulianto-PC', >> 'SERVER_PORT': '8000', >> 'SERVER_PROTOCOL': 'HTTP/1.1', >> 'SERVER_SOFTWARE': 'WSGIServer/0.1 Python/2.7.2', >> 'SESSIONNAME': 'Console', >> 'SSLEAY_CONF': 'd:\\apache2triad\\opssl\\bin', >> 'SYSTEMDRIVE': 'C:', >> 'SYSTEMROOT': 'C:\\Windows', >> 'TEMP': 'C:\\Users\\mulianto\\AppData\\Local\\Temp', >> 'TMP': 'C:\\Users\\mulianto\\AppData\\Local\\Temp', >> 'USERDOMAIN': 'mulianto-PC', >> 'USERNAME': 'mulianto', >> 'USERPROFILE': 'C:\\Users\\mulianto', >> 'VBOX_INSTALL_PATH': 'C:\\Program Files\\Oracle\\VirtualBox\\', >> 'WINDIR': 'C:\\Windows', >> 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x012050D0>, >> 'wsgi.file_wrapper': <class 'django.core.servers.basehttp.FileWrapper'>, >> 'wsgi.input': <socket._fileobject object at 0x028E09B0>, >> 'wsgi.multiprocess': False, >> 'wsgi.multithread': True, >> 'wsgi.run_once': False, >> 'wsgi.url_scheme': 'http', >> 'wsgi.version': (1, 0)}> >> >> callback >> >> <function myadmin_change_post at 0x028ECC70> >> >> resolver >> >> <RegexURLResolver myblog.urls (None:None) ^/> >> >> urlresolvers >> >> <module 'django.core.urlresolvers' from >> 'c:\python27\lib\site-packages\django\core\urlresolvers.pyc'> >> >> callback_kwargs >> >> {'template_name': 'blog/admin/change_post.html'} >> >> response >> >> None >> >> urlconf >> >> 'myblog.urls' >> >> C:\Users\mulianto\workspace\myblog\src\myblog\..\myblog\article\views.py in >> myadmin_change_post >> >> def myadmin_change_post(request, >> template_name='blog/admin/change_post.html'): >> >> try: >> >> id= request.GET.get('id','4') >> >> except ValueError: >> >> id=1 >> >> #post = get_object_or_404(Post,pk=id) >> >> post = Post.objects.get(pk=id) >> >> form = AdminPostForm(instance=post) >> >> ... >> >> return render_to_response(template_name,locals(),context_instance = >> RequestContext(request) ) >> >> def myadmin_new_post(request, template_name="blog/admin/change_post.html"): >> >> if request.method == 'POST': # If the form has been submitted... >> >> form = AdminPostForm(request.POST) # A form bound to the POST data >> >> if form.is_valid(): # All validation rules pass >> >> ▶ Local vars >> >> On Mon, Aug 15, 2011 at 2:06 AM, Daniel Roseman <dan...@roseman.org.uk> >> wrote: >>> >>> This line: >>> form = AdminPostForm(initial=post) >>> >>> should be >>> form = AdminPostForm(instance=post) >>> >>> -- >>> DR. >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Django users" group. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msg/django-users/-/aasgmM81VrgJ. >>> To post to this group, send email to django-users@googlegroups.com. >>> To unsubscribe from this group, send email to >>> django-users+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/django-users?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.