English 中文(简体)
当我揭开行政.autodiscover()时,大物体就没有属性。
原标题: str object has no attribute _meta error come when I uncomment admin.autodiscover()

我正面临这一错误:

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 
最佳回答

The issue is this line:

admin.site.register( Product ,  ProductAdmin )

你们必须穿上班物体,而不是str。 这一工作应当:

admin.site.register(Product, ProductAdmin)
问题回答

暂无回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签