我正面临这一错误:
AttributeError at /
str object has no attribute _meta
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.3
Exception Type: AttributeError
Exception Value:
str object has no attribute _meta
Exception Location: C:Python27libsite-packagesdjangocontribadminsites.py in register, line 80
Python Executable: C:Python27python.exe
Python Version: 2.7.2
Python Path: [ D:\programming\django_projects\ecomstore ,
C:\Python27\lib\site-packages\setuptools-0.6c9-py2.7.egg ,
C:\Python27\lib\site-packages\pymysql-0.3-py2.6.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: Fri, 13 Jan 2012 16:44:18 +0500
如果我评论<条码>admin.autodiscover()的话,那么这种错误就会出现。 示范法如下:
from django import forms
from catalog.models import Product
class ProductAdminForm(forms.ModelForm):
class Meta:
model=Product
def clean_price(self):
if self.cleaned_data[ price ]<=0:
raise forms.ValidationError( Price must be greater than zero )
return self.cleaned_data[ price ]
因此,如果有人理解这个问题,请说明。
下面是追溯:
Environment:
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.3
Python Version: 2.7.2
Installed Applications:
[ django.contrib.auth ,
django.contrib.contenttypes ,
django.contrib.sessions ,
django.contrib.sites ,
django.contrib.messages ,
django.contrib.staticfiles ,
django.contrib.admin ,
ecomstore.catalog ]
Installed Middleware:
( django.middleware.common.CommonMiddleware ,
django.contrib.sessions.middleware.SessionMiddleware ,
django.middleware.csrf.CsrfViewMiddleware ,
django.contrib.auth.middleware.AuthenticationMiddleware ,
django.contrib.messages.middleware.MessageMiddleware )
Traceback:
File "C:Python27libsite-packagesdjangocorehandlersase.py" in get_response
101. request.path_info)
File "C:Python27libsite-packagesdjangocoreurlresolvers.py" in resolve
250. for pattern in self.url_patterns:
File "C:Python27libsite-packagesdjangocoreurlresolvers.py" in _get_url_patterns
279. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:Python27libsite-packagesdjangocoreurlresolvers.py" in _get_urlconf_module
274. self._urlconf_module = import_module(self.urlconf_name)
File "C:Python27libsite-packagesdjangoutilsimportlib.py" in import_module
35. __import__(name)
File "D:programmingdjango_projectsecomstore..ecomstoreurls.py" in <module>
5. admin.autodiscover()
File "C:Python27libsite-packagesdjangocontribadmin\__init__.py" in autodiscover
26. import_module( %s.admin % app)
File "C:Python27libsite-packagesdjangoutilsimportlib.py" in import_module
35. __import__(name)
File "D:programmingdjango_projectsecomstore..ecomstorecatalogadmin.py" in <module>
19. admin.site.register( Product , ProductAdmin )
File "C:Python27libsite-packagesdjangocontribadminsites.py" in register
80. if model._meta.abstract:
Exception Type: AttributeError at /
Exception Value: str object has no attribute _meta