Python stacktrace帮助

时间:2009-12-10 14:54:24

标签: python django stack-trace

当我尝试在我的Python网站上查看一些数据时,我有这个堆栈跟踪错误,有人可以告诉我这是什么问题我很丢失

   Environment:

Request Method: GET
Request URL: http://mywesbite.genericdomain.co.uk/admin/shop/passwordresetrequest/4/
Django Version: 1.1.1
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.admin',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'mywebsite.news',
 'mywebsite.store_locator',
 'mywebsite.css_switch',
 'mywebsite.professional',
 'mywebsite.contact',
 'mywebsite.shop',
 'tinymce',
 'captcha']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Template error:
In template /usr/lib/python2.5/site-packages/django/contrib/admin/templates/admin/change_form.html, error at line 20
   Caught an exception while rendering: 'PasswordResetRequest' object has no attribute 'date'
   10 : 


   11 : {% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}


   12 : 


   13 : {% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}


   14 : 


   15 : {% block breadcrumbs %}{% if not is_popup %}


   16 : <div class="breadcrumbs">


   17 :      <a href="../../../">{% trans "Home" %}</a> &rsaquo;


   18 :      <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo; 


   19 :      {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo; 


   20 :      {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %} {{ original|truncatewords:"18" }} {% endif %}


   21 : </div>


   22 : {% endif %}{% endblock %}


   23 : 


   24 : {% block content %}<div id="content-main">


   25 : {% block object-tools %}


   26 : {% if change %}{% if not is_popup %}


   27 :   <ul class="object-tools"><li><a href="history/" class="historylink">{% trans "History" %}</a></li>


   28 :   {% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}


   29 :   </ul>


   30 : {% endif %}{% endif %}


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in root
  490.                 return self.model_page(request, *url.split('/', 2))
File "/usr/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in model_page
  509.         return admin_obj(request, rest_of_url)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in __call__
  1098.             return self.change_view(request, unquote(url))
File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in _commit_on_success
  240.                 res = func(*args, **kw)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in change_view
  873.         return self.render_change_form(request, context, change=True, obj=obj)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in render_change_form
  590.         ], context, context_instance=context_instance)
File "/usr/lib/python2.5/site-packages/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/lib/python2.5/site-packages/django/template/loader.py" in render_to_string
  108.     return t.render(context_instance)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  243.                     return self.nodelist_true.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  243.                     return self.nodelist_true.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  244.             return self.nodelist_false.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  81.             raise wrapped

Exception Type: TemplateSyntaxError at /admin/shop/passwordresetrequest/4/
Exception Value: Caught an exception while rendering: 'PasswordResetRequest' object has no attribute 'date'

Original Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/usr/lib/python2.5/site-packages/django/template/debug.py", line 87, in render
    output = force_unicode(self.filter_expression.resolve(context))
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 572, in resolve
    new_obj = func(obj, *arg_vals)
  File "/usr/lib/python2.5/site-packages/django/template/defaultfilters.py", line 37, in _dec
    args[0] = force_unicode(args[0])
  File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line 71, in force_unicode
    s = unicode(s)
  File "/var/www/mywesbite/src/mywebsite/../mywesbite/shop/models.py", line 1105, in __unicode__
    return ", ".join((str(self.account),self.date.strftime("%b. %d, %Y, %H:%M %p")))
AttributeError: 'PasswordResetRequest' object has no attribute 'date'

我的模特

class Account(BaseAccount):
    """
    The account is an extension of the Django user and serves as the profile
    object in user.get_profile() for shop purchases and sessions
    """
    telephone = models.CharField(max_length=32)
    default_address = models.ForeignKey(Address, related_name='billing_account', blank=True, null=True)
    security_question = models.ForeignKey(SecurityQuestion)
    security_answer = models.CharField(max_length=200)
    how_heard = models.CharField("How did you hear about us?", max_length=100)
    feedback = models.TextField(blank=True)
    opt_in = models.BooleanField("Subscribe to mailing list", help_text="Please tick here if you would like to receive updates from %s" % Site.objects.get_current().name)
    temporary = models.BooleanField()

    def has_placed_orders(self):
        """
        Returns True if the user has placed at least one order, False otherwise
        """
        return self.order_set.count() > 0

    def get_last_order(self):
        """
        Returns the latest order that this customer has placed. If no orders
        have been placed, then None is returned
        """
        try:
            return self.order_set.all().order_by('-date')[0]
        except IndexError:
            return None

    def get_currency(self):
        """
        Get the currency for this customer. If global currencies are enabled
        (settings.ENABLE_GLOBAL_CURRENCIES) then this function will return
        the currency related to their default address, otherwise, it returns
        the site default
        """
        if settings.ENABLE_GLOBAL_CURRENCIES:
            return self.default_address.country.currency
        return Currency.get_default_currency()
    currency = property(get_currency)

    def get_gateway_currency(self):
        """
        Get the currency that an order will be put through protx with. If protx
        currencies are enabled (settings.ENABLE_PROTX_CURRENCIES), then the
        currency will be the same returned by get_currency, otherwise, the
        site default is used
        """
        if settings.ENABLE_PROTX_CURRENCIES and settings.ENABLE_GLOBAL_CURRENCIES:
            return self.currency
        return Currency.get_default_currency()
    gateway_currency = property(get_gateway_currency)


    def password_reset_presave(sender, **kwargs):
        """
        This pre-save is responsible for generating a unique key for the request
        before it is saved to DB.
        """
        instance = kwargs['instance']
        if not instance.key:
            instance.generate_key()

class PasswordResetRequest(models.Model):
    """
    Stores a history of all of the password reset requests that have been
    issued across the site. It is also used to validate resets against a given
    URL given the key.
    """
    account = models.ForeignKey(Account)
    key = models.CharField(max_length=100, unique=True)
    issued = models.DateTimeField(auto_now_add=True)
    used = models.BooleanField()

    def is_valid(self):
        """
        Is this password reset request still valid? Returns true if it hasn't
        yet been successfully used, and was issued any time within the last
        seven days
        """
        return not self.used and datetime.datetime.now() < self.issued + datetime.timedelta(days=7)

    def __unicode__(self):
        """
        The unicode representation of this password reset request. It is build
        using the unicode representation of the customers account, plus the
        date and time the request was made, in string form
        """
        return ", ".join((str(self.account),self.issued.strftime("%b. %d, %Y, %H:%M %p")))

    def generate_key(self):
        """
        Generate a uuid4 key and assign it to this objects key attribute
        """
        from uuid import uuid4
        self.key = uuid4()

    class Meta:
        """
        Django meta options

        verbose_name = "Password Reset Request"
        verbose_name_plural = "Password Reset Requests"
        """
        verbose_name = "Password Reset Request"
        verbose_name_plural = "Password Reset Requests"

pre_save.connect(password_reset_presave, sender=PasswordResetRequest)

4 个答案:

答案 0 :(得分:5)

重要的部分是在最后几行(请记住,最近的一次调用,即:导致错误的一次,始终在堆栈跟踪中打印出来):

  File "/var/www/mywesbite/src/mywebsite/../mywesbite/shop/models.py", line 1105, in     
  __unicode__
  return ", ".join((str(self.account),self.date.strftime("%b. %d, %Y, %H:%M %p")))
  AttributeError: 'PasswordResetRequest' object has no attribute 'date'

这意味着,在第1105行(在mywebsite/shop/models.py方法中)的文件def __unicode__(self):中,您正在调用self.date.strftime(),但该模型没有名为{的属性{1}}。

答案 1 :(得分:1)

看最后一行:

/var/www/mywesbite/src/mywebsite/../mywesbite/shop/models.py

__unicode__方法中有一行:

return ", ".join((str(self.account),self.date.strftime("%b. %d, %Y, %H:%M %p")))

self不知道date属性。也许没有定义。 如果您不确定,请更改此特定的return语句以返回无意义但暂时无误的内容,并查看是否是唯一的错误。

答案 2 :(得分:0)

问题出在shop / models.py中定义的PasswordResetRequest模型的 unicode 方法中。您尝试访问此对象上的self.date,但它没有日期属性。

也许如果您粘贴模型我可以提供更多帮助......

答案 3 :(得分:0)

没有提及日期的参考