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<http://127.0.0.1:8000/article/change/?id=2#> - c:\python27\lib\site-packages\django\core\handlers\base.py in get_response 1. for middleware_method in self._view_middleware: 2. response = middleware_method(request, callback, callback_args, callback_kwargs) 3. if response: 4. break 5. 6. if response is None: 7. try: 1. response = callback(request, *callback_args, **callback_kwargs) ... 1. except Exception, e: 2. # If the view raised an exception, run it through exception 3. # middleware, and if the exception middleware returns a 4. # response, use that. Otherwise, reraise the exception. 5. for middleware_method in self._exception_middleware: 6. response = middleware_method(request, e) ▶ Local vars <http://127.0.0.1:8000/article/change/?id=2#> 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.pyin myadmin_change_post 1. def myadmin_change_post(request, template_name='blog/admin/change_post.html'): 2. try: 3. id= request.GET.get('id','4') 4. except ValueError: 5. id=1 6. #post = get_object_or_404(Post,pk=id) 7. post = Post.objects.get(pk=id) 1. form = AdminPostForm(instance=post) ... 1. return render_to_response(template_name,locals(),context_instance = RequestContext(request) ) 2. 3. def myadmin_new_post(request, template_name="blog/admin/change_post.html"): 4. if request.method == 'POST': # If the form has been submitted... 5. form = AdminPostForm(request.POST) # A form bound to the POST data 6. if form.is_valid(): # All validation rules pass ▶ Local vars <http://127.0.0.1:8000/article/change/?id=2#> 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.