我有一個讓我發瘋的問題。我使用內置的服務器開發了一個django應用程序,現在正在嘗試將它部署到apache 2.2後面的生產服務器上。Django'unicode'對象沒有屬性'year'
我已經將數據庫從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'
周圍的錯誤和環境方面表明data_range變量是回來爲一個字符串,但它的代碼預期是DateTime對象:
<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/
是觸發上面的錯誤,但只在生產服務器上。任何線索?還有更多你需要的信息嗎?
您能否正確縮進您的代碼? –
更好嗎?我仍然在這裏使用格式。 –