我需要爲一組操作顯示用戶的提要。我爲此使用了Django Activity Stream。我剛開始測試應用程序,但似乎無法顯示用戶供稿。ValueError at/feed/- int()與基數爲10的無效文字
由於每Action Stream documentation我使用的actor_stream
功能如下
from actstream.models import actor_stream
def user_feed(request):
print actor_stream(request.user)
這給了我一個錯誤
ValueError at /feed/
invalid literal for int() with base 10: '<property object at 0x2a6a520>'
這裏是回溯
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/jaskaran/coding/buyingiq/authentication/feed/views.py" in user_feed
7. print actor_stream(request.user)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __repr__
71. data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __iter__
96. self._fetch_all()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _fetch_all
856. self._prefetch_related_objects()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _prefetch_related_objects
517. prefetch_related_objects(self._result_cache, self._prefetch_related_lookups)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in prefetch_related_objects
1598. obj_list, additional_prl = prefetch_one_level(obj_list, prefetcher, attr)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in prefetch_one_level
1697. prefetcher.get_prefetch_queryset(instances)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/generic.py" in get_prefetch_queryset
96. ret_val.extend(ct.get_all_objects_for_this_type(pk__in=fkeys))
File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/models.py" in get_all_objects_for_this_type
174. return self.model_class()._base_manager.using(self._state.db).filter(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in filter
590. return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _filter_or_exclude
608. clone.query.add_q(Q(*args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in add_q
1198. clause = self._add_q(where_part, used_aliases)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in _add_q
1234. current_negated=current_negated)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in build_filter
1125. clause.add(constraint, AND)
File "/usr/local/lib/python2.7/dist-packages/django/utils/tree.py" in add
104. data = self._prepare_data(data)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/where.py" in _prepare_data
79. value = obj.prepare(lookup_type, value)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/where.py" in prepare
352. return self.field.get_prep_lookup(lookup_type, value)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py" in get_prep_lookup
371. return [self.get_prep_value(v) for v in value]
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py" in get_prep_value
613. return int(value)
Exception Type: ValueError at /feed/
Exception Value: invalid literal for int() with base 10: '<property object at 0x2a6a520>'
print type(actor_stream(request.user))
評估爲<class 'actstream.gfk.GFKQuerySet'>
我甚至試圖將它作爲一個列表打印,然後打印它,但它仍然會拋出相同的錯誤。我應該如何在我的視圖中訪問演員流?
編輯 - 我使用自定義用戶模型,如果有任何區別。
EDIT 2 - 回溯使用艾略特的解決方案
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
101. resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
318. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
346. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
341. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
40. __import__(name)
File "/home/jaskaran/coding/buyingiq/authentication/authentication/urls.py" in <module>
7. admin.autodiscover()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py" in autodiscover
29. import_module('%s.admin' % app)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
40. __import__(name)
File "/usr/local/lib/python2.7/dist-packages/allauth/account/admin.py" in <module>
9. class EmailAddressAdmin(admin.ModelAdmin):
File "/usr/local/lib/python2.7/dist-packages/allauth/account/admin.py" in EmailAddressAdmin
16. 'last_name'])))
File "/usr/local/lib/python2.7/dist-packages/allauth/account/admin.py" in <lambda>
13. filter(lambda a: a and hasattr(User(), a),
File "/home/jaskaran/coding/buyingiq/authentication/users/models.py" in __init__
86. return self.pk
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in _get_pk_val
465. return getattr(self, meta.pk.attname)
Exception Type: AttributeError at /feed/
Exception Value: 'UserProfile' object has no attribute 'id'
你有沒有設法解決這個問題?我也遇到了這個問題 –