Уведомления

Группа в Telegram: @pythonsu
  • Начало
  • » Django
  • » ошибкAttributeError: 'SafeString' object has no attribute 'has_header' [RSS Feed]

#1 Июнь 4, 2008 13:34:37

romankrv
От:
Зарегистрирован: 2008-05-23
Сообщения: 513
Репутация: +  0  -
Профиль   Отправить e-mail  

ошибкAttributeError: 'SafeString' object has no attribute 'has_header'

при обращении к 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’

Офлайн

#2 Июнь 4, 2008 14:01:45

playpauseandstop
От:
Зарегистрирован: 2007-10-31
Сообщения: 77
Репутация: +  0  -
Профиль   Отправить e-mail  

ошибкAttributeError: 'SafeString' object has no attribute 'has_header'

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')



Офлайн

  • Начало
  • » Django
  • » ошибкAttributeError: 'SafeString' object has no attribute 'has_header'[RSS Feed]

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version