2016-12-21 11 views
0

私はDjango 1.7で書かれたDjangoアプリを持っています。私はDockerアプリに移植しています。私はコンテナ内でDjango 1.10を使用しています。Django 1.10 KeyError at/admin/

私は/管理/ URIを参照すると、私は次の例外を取得:

KeyError at /admin/ 

u'user' 

Request Method:  GET 
Request URL:  http://10.3.101.206:9000/admin/ 
Django Version:  1.10 
Exception Type:  KeyError 
Exception Value:  

u'user' 

Exception Location:  /usr/local/lib/python2.7/site-packages/django/template/context.py in __getitem__, line 75 
Python Executable: /usr/local/bin/python 
Python Version:  2.7.12 
Python Path:  

['/var/www/django/labmgr', 
'/usr/local/lib/python27.zip', 
'/usr/local/lib/python2.7', 
'/usr/local/lib/python2.7/plat-linux2', 
'/usr/local/lib/python2.7/lib-tk', 
'/usr/local/lib/python2.7/lib-old', 
'/usr/local/lib/python2.7/lib-dynload', 
'/usr/local/lib/python2.7/site-packages'] 

Server time: Tue, 20 Dec 2016 21:43:21 -0800 

Error during template rendering 

In template /usr/local/lib/python2.7/site-packages/django/contrib/admin/templates/admin/index.html, error at line 58 
user 

48 {% endif %} 
49 </div> 
50 {% endblock %} 
51 
52 {% block sidebar %} 
53 <div id="content-related"> 
54  <div class="module" id="recent-actions-module"> 
55   <h2>{% trans 'Recent actions' %}</h2> 
56   <h3>{% trans 'My actions' %}</h3> 
57    {% load log %} 
58    {% get_admin_log 10 as admin_log for_user user %} 
59    {% if not admin_log %} 
60    <p>{% trans 'None available' %}</p> 
61    {% else %} 
62    <ul class="actionlist"> 
63    {% for entry in admin_log %} 
64    <li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}"> 
65     {% if entry.is_deletion or not entry.get_admin_url %} 
66      {{ entry.object_repr }} 
67     {% else %} 
68      <a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a> 

エラーはDjangoのコードではなく、私のコードにあるように見えるので、私はわからないんだけど問題は解決方法です。

答えて

2

KeyErrorコンテキスト変数が見つかりませんでした。この変数は、通常はデフォルトで含まれているdjango.contrib.auth.context_processors.authによってのみ利用できます。 hereを説明するようにあなたのコンテキストプロセッサに含めることができ

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [ 
      # insert your TEMPLATE_DIRS here 
     ], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
       'django.contrib.auth.context_processors.auth', 
       # ...list other context processors you will need... 
      ], 
     }, 
    }, 
] 
+1

感謝。私はDjangoのコードをアップグレードしましたが、古いコードと設定を移行したので、私の設定でデフォルト値を取得しませんでした。 – zoidberg

関連する問題