2017-04-09 5 views
0

다음은 내 블로그 RSS 피드를 생성하는 내 장고 1.10 views.py 코드입니다. 나는 이제 이것에 추적 내 사용 통계를 추가하려고합니다.'NoneType'객체에는 'META'속성이 없습니다.

모든 통계 코드를 내 프로젝트의 지정된 영역에 보관합니다. 내가 필요로하는 모든 내용은 rss views.py에있는 3 줄의 코드입니다. 이건 내 다른 views.py에서 작동하는데, 현재 RSS에있는 것은 아닙니다.

from statistics.service.add import ServiceAdd as ServiceStatisticsAdd 
rss_reference = {'utc': timezone.now()} 
ServiceStatisticsAdd(request).add('rss', rss_reference, kwargs) 

내가 점점 오전 오류는 모든 약 요청입니다. 원래 데이터베이스 def는 def 항목 (자기) :입니다. 내가 요청을 포함하여 예상 추적을 추가 할 때 오류가 수정되었을 것입니다.

이이 전체 역 추적

[09/Apr/2017 14:02:48] "GET/HTTP/1.1" 302 0 
/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField BlogWebsite.entry_date received a naive datetime (2017-04-09 14:02:48) while time zone support is active. 
    RuntimeWarning) 
/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField NewsletterEditions.issue_date received a naive datetime (2017-04-09 14:02:48) while time zone support is active. 
    RuntimeWarning) 
/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField VideoProfile.date_created received a naive datetime (2017-04-09 14:02:48) while time zone support is active. 
    RuntimeWarning) 
[09/Apr/2017 14:02:48] "GET /en/ HTTP/1.1" 200 20414 
/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField BlogWebsite.entry_date received a naive datetime (2017-04-09 14:02:51.335566) while time zone support is active. 
    RuntimeWarning) 
[09/Apr/2017 14:02:51] "GET /en/blog/ HTTP/1.1" 200 21780 
Internal Server Error: /en/rss/blog 
Traceback (most recent call last): 
    File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 42, in inner 
    response = get_response(request) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 187, in _get_response 
    response = self.process_exception_by_middleware(e, request) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 185, in _get_response 
    response = wrapped_callback(request, *callback_args, **callback_kwargs) 
    File "/usr/local/lib/python3.5/dist-packages/django/contrib/syndication/views.py", line 41, in __call__ 
    feedgen = self.get_feed(obj, request) 
    File "/usr/local/lib/python3.5/dist-packages/django/contrib/syndication/views.py", line 169, in get_feed 
    for item in self._get_dynamic_attr('items', obj): 
    File "/usr/local/lib/python3.5/dist-packages/django/contrib/syndication/views.py", line 92, in _get_dynamic_attr 
    return attr(obj) 
    File "/home/rpiggott/PyCharmProjects/rons-home.net/rss/views.py", line 27, in items 
    ServiceStatisticsAdd(request).add('rss', rss_reference, kwargs) 
    File "/usr/lib/python3.5/contextlib.py", line 30, in inner 
    return func(*args, **kwds) 
    File "/home/rpiggott/PyCharmProjects/rons-home.net/statistics/service/add.py", line 25, in add 
    ip_address = get_real_ip(self.request) 
    File "/usr/local/lib/python3.5/dist-packages/ipware/ip.py", line 36, in get_real_ip 
    return get_ip(request, real_ip_only=True, right_most_proxy=right_most_proxy) 
    File "/usr/local/lib/python3.5/dist-packages/ipware/ip.py", line 14, in get_ip 
    value = request.META.get(key, request.META.get(key.replace('_', '-'), '')).strip() 
AttributeError: 'NoneType' object has no attribute 'META' 
[09/Apr/2017 14:02:54] "GET /en/rss/blog HTTP/1.1" 500 114831 
+0

당신의'ServiceStatisticsAdd' 기능이있어이 방법을 추가 하시겠습니까? 요청에 따라 올바르게 전달 했습니까? – Bobby

+0

@Bobby 나는이 3 줄의 코드를 다른 views.py에서 복사했습니다. 그들은 옳다. 실제 ServiceStatisticsAdd는 '통계'하위 모듈에 있습니다. –

답변

1

내가 조금 까다 롭습니다 생각 내 views.py

from datetime import datetime 

from django.contrib.syndication.views import Feed 
from django.urls import reverse 
from django.utils import timezone 

from database.ron_home.models import BlogWebsite 
from statistics.service.add import ServiceAdd as ServiceStatisticsAdd 


class BlogRssFeed(Feed): 
    title = "Rons-Home.net Blog RSS Feed" 
    link = "/en/blog/" 
    description = "Ron Piggott shares updates from his health care and logistics of daily living with a physical disability." 

    def item_title(self, obj): 
     return obj.entry_title 

    def item_description(self, obj): 
     return obj.entry 

    def item_link(self, obj): 
     return reverse('blog:entry', args=[obj.reference]) 

    def items(self, request, **kwargs): 
     rss_reference = {'utc': timezone.now()} 
     ServiceStatisticsAdd(request).add('rss', rss_reference, kwargs) 
     return BlogWebsite.objects.filter(entry_date__lt=datetime.utcnow()).order_by('-entry_date')[:15] 

입니다. 그런 다음 BlogRssFeed

def get_feed(self, obj, request): 
    self.custom_var = request 
    return super().get_feed(obj, request) 

ServiceStatisticsAdd(self.custom_var).add('rss', rss_reference, kwargs) 
+0

일부 해킹 방법을 업데이트했습니다. – itzMEonTV

+0

감사합니다. 정말 감사. –