Reputation: 11
First question asked in stack overflow here.
So, I am starting a few Django projects and ended up with this issue:
AttributeError: 'function' object has no attribute 'path'
Which happens on the following context processor:
def get_request_promotions(request):
promotions = PagePromotion._default_manager.select_related() \
.prefetch_related('content_object') \
.filter(page_url=request.path) \
.order_by('display_order')
if 'q' in request.GET:
keyword_promotions \
= KeywordPromotion._default_manager.select_related()\
.filter(keyword=request.GET['q'])
if keyword_promotions.exists():
promotions = list(chain(promotions, keyword_promotions))
return render(promotions, request)
That is, Django isn't able to find the path object on request. This is my context processors in settings.py
:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'), ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request', # For EL-pagination
'common.core.context_processors.metadata',
'portfolio.search.context_processors.search_form',
'store.promotions.context_processors.promotions',
'store.checkout.context_processors.checkout',
'common.accounts.notifications.context_processors.notifications',
],
},
},
]
Any hints?
Upvotes: 0
Views: 519
Reputation: 11
Hmm, to all who might be interested in this question, the problem was with the 'render' method. Technically, a function based view must return a HttpResponse object, and render just does not do that.
I've changed the last code line to
return render_to_response(promotions, request)
and it worked like a charm.
Upvotes: 1