Getting error on redirect django
<p>What am I trying to do is </p>

<p>if a user comes with a slug </p>

<p>Case 1</p>

<p>'new' I am either creating a new box for him or fetching his existing empty box and redirecting him based on the slug of the box</p>

<p>Case 2</p>

<p>anything else works fine</p>

<p>URL pattern is </p>

<pre><code>url(r'^box/manage/(?P&lt;slug&gt;.*)/$', login_required(views.ManageBoxView.as_view()), name='manage_box'),
</code></pre>

<p>I am getting an error </p>

<blockquote>
  <p>dict' object has no attribute 'has_header'</p>
</blockquote>

<pre><code>class ManageBoxView(TemplateView):
  template_name = "art/manage_box.html"

  def get(self, request, **kwargs):
    if kwargs['slug'] == 'new':
      box = Box.get_or_create_empty_box(self.request.user)
      return redirect('manage_box', slug= box.slug)
    else:
      box = Box.objects.get(slug=kwargs['slug'])
      return {'box': box, 'drafts': box.drafts}
</code></pre>

<p>Stack Trace</p>

<pre><code>Environment:

Request Method: GET
Request URL: http://localhost:8000/box/manage/10-untitled-admin/

Django Version: 1.7.4
Python Version: 2.7.11
Installed Applications:
('django_admin_bootstrapped',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.messages',
 'django.contrib.sites',
 'django.contrib.humanize',
 'django.contrib.staticfiles',
 'gunicorn',
 'rest_framework',
 'imagekit',
 'utils',
 'users',
 'arts',
 'notification',
 'connect',
 'payment',
 'products',
 'orders',
 'social')
Installed Middleware:
('sslify.middleware.SSLifyMiddleware',
 'django.middleware.gzip.GZipMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'raygun4py.middleware.django.Provider')


Traceback:
File "/home/cj/.vrtualenvs/canvs/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  204.                 response = middleware_method(request, response)
File "/home/cj/.vrtualenvs/canvs/local/lib/python2.7/site-packages/django/contrib/sessions/middleware.py" in process_response
  30.                 patch_vary_headers(response, ('Cookie',))
File "/home/cj/.vrtualenvs/canvs/local/lib/python2.7/site-packages/django/utils/cache.py" in patch_vary_headers
  148.     if response.has_header('Vary'):

Exception Type: AttributeError at /box/manage/10-untitled-admin/
Exception Value: 'dict' object has no attribute 'has_header'
</code></pre>

<p>In the else condition of the get method, you are trying to return an object instead of a response. You have to return a response like <code>return render(request, template_name, {'box': box, 'drafts': box.drafts})</code> instead of <code>return {'box': box, 'drafts': box.drafts}</code> .</p>

python django django-1.7