Latest posts on ошибкAttributeError: 'SafeString' object has no attribute 'has_header' topichttps://python.su/forum/topic/2182/2008-06-04T14:01:45+03:00Веб-технологии :: Django :: ошибкAttributeError: 'SafeString' object has no attribute 'has_header'
2008-06-04T14:01:45+03:00playpauseandstop13651<a href="http://www.djangoproject.com/documentation/request_response/#quick-overview">Django documentation: Request and response objects</a><br/><blockquote>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 <strong>is responsible</strong> for returning an HttpResponse object.</blockquote>т.е. переводя на русский, каждый view должен отдавать HttpResponse или его подкласс, а не что-либо еще…<br/><div class="code"><pre><span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">HttpResponse</span>
<span class="k">def</span> <span class="nf">sample</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
<span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="s">'This is plain text'</span><span class="p">,</span> <span class="n">mimetype</span><span class="o">=</span><span class="s">'text/plain'</span><span class="p">)</span>
</pre></div>
Веб-технологии :: Django :: ошибкAttributeError: 'SafeString' object has no attribute 'has_header'
2008-06-04T13:34:37+03:00romankrv13649при обращении к <a href="http://127.0.0.1:8000/test">http://127.0.0.1:8000/test</a> <br/>происходит ошибка AttributeError: ‘SafeString’ object has no attribute ‘has_header’ с чем это связанно и как бороть этот ‘has_header’ ? изучаю тему Процессоры RequestContext и Context<br/><br/>code views.py<br/>from django.template import loader, RequestContext<br/><br/>def custom_proc(request):<br/> return {<br/> ‘app’: ‘My app’,<br/> ‘user’: request.user,<br/> }<br/><br/>def view_1(request):<br/> t = loader.get_template('template1.html')<br/> c = RequestContext(request, {'message': ‘I am view 1.’},<br/> processors=)<br/> return t.render©<br/><br/>_______________________<br/>в urls.py code:<br/>from django.conf.urls.defaults import *<br/>from django.views.generic import *<br/>from django.shortcuts import *<br/>from django.http import *<br/>from mysite.books.models import *<br/>from mysite.books.views import *<br/>from django.core.context_processors import *<br/><br/>urlpatterns = patterns('',<br/> (r'^test$', view_1)<br/>)<br/><br/>__________________<br/><br/>Traceback (most recent call last):<br/><br/> File “/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py”, line 277, in run<br/> self.result = application(self.environ, self.start_response)<br/><br/> File “/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py”, line 631, in __call__<br/> return self.application(environ, start_response)<br/><br/> File “/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py”, line 209, in __call__<br/> response = middleware_method(request, response)<br/><br/> File “/usr/lib/python2.5/site-packages/django/contrib/sessions/middleware.py”, line 27, in process_response<br/> patch_vary_headers(response, ('Cookie',))<br/><br/> File “/usr/lib/python2.5/site-packages/django/utils/cache.py”, line 129, in patch_vary_headers<br/> if response.has_header('Vary'):<br/><br/>AttributeError: ‘SafeString’ object has no attribute ‘has_header’