0

我有一个让我发疯的问题。我已经使用内置服务器开发了一个 django 应用程序,现在正尝试将它部署在 apache 2.2 后面的生产服务器上。

我已将数据库从 SQLite 迁移到 PostgreSQL。

在 Django Admin 中,当我在测试服务器上加载 File 对象的“change_list”视图时,它加载得很好。只要我在生产服务器上做同样的事情,我就会得到以下信息:

AttributeError at /admin/wilder/file/

'unicode' object has no attribute 'year'

Request Method: GET
Request URL: https://<snip>.berkeley.edu/<snip>/admin/wilder/file/
Django Version: 1.4.1
Exception Type: AttributeError
Exception Value: 

'unicode' object has no attribute 'year'

Exception Location: <snip>/virtualenv/wilder/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py in date_hierarchy, line 302
Python Executable: <snip>/virtualenv/wilder/bin/uwsgi
Python Version: 2.7.5
Python Path: 

['<snip>/virtualenv/wilder/lib/python2.7/:<snip>/virtualenv/wilder/lib/python2.7/site-packages/:<snip>/ecog_patient_db',
 '.',
 '',
 '<snip>/virtualenv/wilder/lib/python2.7/site-packages/readline-6.2.4.1-py2.7-linux-x86_64.egg',
 '<snip>/virtualenv/wilder/lib/python27.zip',
 '<snip>/virtualenv/wilder/lib/python2.7',
 '<snip>/virtualenv/wilder/lib/python2.7/plat-linux2',
 '<snip>/virtualenv/wilder/lib/python2.7/lib-tk',
 '<snip>/virtualenv/wilder/lib/python2.7/lib-old',
 '<snip>/virtualenv/wilder/lib/python2.7/lib-dynload',
 '/home/knight/king/local/lib/python2.7',
 '/home/knight/king/local/lib/python2.7/plat-linux2',
 '/home/knight/king/local/lib/python2.7/lib-tk',
 '<snip>/virtualenv/wilder/lib/python2.7/site-packages',
 '<snip>/virtualenv/wilder/lib/python2.7/site-packages/PIL']

Server time: Wed, 25 Sep 2013 14:41:30 -0700



Error during template rendering

In template /<snip>/ecog_patient_db/templates/admin/change_list.html, error at line 90
'unicode' object has no attribute 'year'
80 {% endif %}
81 {% endblock %}
82 {% if cl.formset.errors %}
83 <p class="errornote">
84 {% blocktrans count cl.formset.errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
85 </p>
86 {{ cl.formset.non_form_errors }}
87 {% endif %}
88 <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
89 {% block search %}{% search_form cl %}{% endblock %}
90 {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
91 
92 {% block filters %}
93 {% if cl.has_filters %}
94 <div id="changelist-filter">
95 <h2>{% trans 'Filter' %}</h2>
96 {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
97 </div>
98 {% endif %}
99 {% endblock %}
100 


Environment:


Request Method: GET
Request URL: https://wilder.berkeley.edu/wilder/admin/wilder/file/

Django Version: 1.4.1
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'south',
 'reversion',
 'massadmin',
 'django_extensions',
 'ecog_patient_db.wilder')
Installed Middleware:
('johnny.middleware.LocalStoreClearMiddleware',
 'johnny.middleware.QueryCacheMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.transaction.TransactionMiddleware')


Template error:
In template <snip>/ecog_patient_db/templates/admin/change_list.html, error at line 90
   'unicode' object has no attribute 'year'
   80 :       {% endif %}
   81 :     {% endblock %}
   82 :     {% if cl.formset.errors %}
   83 :         <p class="errornote">
   84 :         {% blocktrans count cl.formset.errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
   85 :         </p>
   86 :         {{ cl.formset.non_form_errors }}
   87 :     {% endif %}
   88 :     <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
   89 :       {% block search %}{% search_form cl %}{% endblock %}
   90 :       {% block date_hierarchy %} {% date_hierarchy cl %} {% endblock %}
   91 : 
   92 :       {% block filters %}
   93 :         {% if cl.has_filters %}
   94 :           <div id="changelist-filter">
   95 :             <h2>{% trans 'Filter' %}</h2>
   96 :             {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
   97 :           </div>
   98 :         {% endif %}
   99 :       {% endblock %}
   100 : 


Traceback:
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  136.                     response = response.render()
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/response.py" in render
  104.             self._set_content(self.rendered_content)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/response.py" in rendered_content
  81.         content = template.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  140.             return self._render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  123.         return compiled_parent._render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  123.         return compiled_parent._render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  1178.                     _dict = func(*resolved_args, **resolved_kwargs)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py" in date_hierarchy
  302.                 if date_range['first'].year == date_range['last'].year:

Exception Type: AttributeError at /admin/wilder/file/
Exception Value: 'unicode' object has no attribute 'year'

错误和 ENVIRONMENT 周围的上下文显示 data_range 变量作为字符串返回,但代码期望它是一个日期时间对象:

<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py in date_hierarchy
            link = lambda d: cl.get_query_string(d, [field_generic])
            if not (year_lookup or month_lookup or day_lookup):
                # select appropriate start level
                date_range = cl.query_set.aggregate(first=models.Min(field_name),
                                                    last=models.Max(field_name))

                if date_range['first'] and date_range['last']:
                    if date_range['first'].year == date_range['last'].year:
                        ...
                        year_lookup = date_range['first'].year
                        if date_range['first'].month == date_range['last'].month:
                            month_lookup = date_range['first'].month

            if year_lookup and month_lookup and day_lookup:
                day = datetime.date(int(year_lookup), int(month_lookup), int(day_lookup))

\u25bc Local vars
Variable Value
month_field 
'file_modification_date__month'

cl 
<django.contrib.admin.views.main.ChangeList object at 0x7f001c142f10>

year_field 
'file_modification_date__year'

field_generic 
'file_modification_date__'

date_range 
{'first': u'2005-01-27 11:05:14', 'last': u'2013-06-12 21:17:45.085712'}

day_field 
'file_modification_date__day'

month_lookup 
None

link 
<function <lambda> at 0x1250e60>

year_lookup 
None

day_lookup 
None

field_name 
'file_modification_date'

我一生都无法弄清楚为什么这会突然在生产系统上失败。如果我添加?file_modification_date__year=2006然后https://<snip>.berkeley.edu/<snip>/admin/wilder/file/?file_modification_date__year=2006正确加载。但是https://<snip>.berkeley.edu/<snip>/admin/wilder/file/是什么触发了上述错误,但仅在生产服务器上。有什么线索吗?你们还需要更多信息吗?

4

1 回答 1

0

嗯,这很烦人。刷新内存缓存就可以了。我正在使用 johnny_cache。

于 2013-09-27T20:22:45.587 回答