Найти - Пользователи
Полная версия: ошибкAttributeError: 'SafeString' object has no attribute 'has_header'
Начало » Django » ошибкAttributeError: 'SafeString' object has no attribute 'has_header'
1
romankrv
при обращении к http://127.0.0.1:8000/test
происходит ошибка AttributeError: ‘SafeString’ object has no attribute ‘has_header’ с чем это связанно и как бороть этот ‘has_header’ ? изучаю тему Процессоры RequestContext и Context

code views.py
from django.template import loader, RequestContext

def custom_proc(request):
return {
‘app’: ‘My app’,
‘user’: request.user,
}

def view_1(request):
t = loader.get_template('template1.html')
c = RequestContext(request, {'message': ‘I am view 1.’},
processors=)
return t.render©

_______________________
в urls.py code:
from django.conf.urls.defaults import *
from django.views.generic import *
from django.shortcuts import *
from django.http import *
from mysite.books.models import *
from mysite.books.views import *
from django.core.context_processors import *

urlpatterns = patterns('',
(r'^test$', view_1)
)

__________________

Traceback (most recent call last):

File “/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py”, line 277, in run
self.result = application(self.environ, self.start_response)

File “/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py”, line 631, in __call__
return self.application(environ, start_response)

File “/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py”, line 209, in __call__
response = middleware_method(request, response)

File “/usr/lib/python2.5/site-packages/django/contrib/sessions/middleware.py”, line 27, in process_response
patch_vary_headers(response, ('Cookie',))

File “/usr/lib/python2.5/site-packages/django/utils/cache.py”, line 129, in patch_vary_headers
if response.has_header('Vary'):

AttributeError: ‘SafeString’ object has no attribute ‘has_header’
playpauseandstop
Django documentation: Request and response objects
When a page is requested, Django creates an HttpRequest object that contains metadata about the request. Then Django loads the appropriate view, passing the HttpRequest as the first argument to the view function. Each view is responsible for returning an HttpResponse object.
т.е. переводя на русский, каждый view должен отдавать HttpResponse или его подкласс, а не что-либо еще…
from django.http import HttpResponse
def sample(request):
    return HttpResponse('This is plain text', mimetype='text/plain')
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB