Django 1.8:/:'str'对象的AttributeError没有属性'copy'

Sea*_*ais 2 python django

我一直在尝试Django 1.8.1.到目前为止,直到我测试它一直很好.当我去localhost:8000Django服务文件的地址()时,我得到错误:
AttributeError at /: 'str' object has no attribute 'copy'

我有一个fb_auth在Django中调用的应用程序.这是目录树.
/path/to/project/directory | ---.gitignore | ---project_foo | ---project_foo ---fb_auth ---templates ---<stuff>

在追溯中,我可以看到这个突出显示的行,这是我的观点. return render(request, 'login.html')

这是我的views.py:

from django.shortcuts import render_to_response, redirect, render    
from django.contrib.auth import logout as auth_logout    
from django.contrib.auth.decorators import login_required    

def login(request):    
    return render(request, 'login.html')    

@login_required(login_url='/')    
def vote(request):    
    return render_to_response('vote.html')    

def logout(request):     
    auth_logout(request)    
    return redirect('/')
Run Code Online (Sandbox Code Playgroud)

这是我的urls.py(如果这有帮助):

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url('', include('social.apps.django_app.urls', namespace='social')),
    url(r'^$', 'fb_auth.views.login'),
    url(r'^vote/$', 'fb_auth.views.vote'),
    url(r'^logout/$', 'fb_auth.views.logout'),
]
Run Code Online (Sandbox Code Playgroud)

这是我的login.html:

{% if user and not user.is_anonymous %}
    <a>Hello, {{ user.get_full_name }}!</a>
    <br>
    <a href="/logout">Logout</a>
{% else %}
    <a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}">Login with Facebook</a>
{% endif %} 
Run Code Online (Sandbox Code Playgroud)

这是我的vote.html(目前):

<h1>Hello vote test</h1>
<p>    
    <a href="/logout">Logout</a>
</p>
Run Code Online (Sandbox Code Playgroud)

这是追溯:

File "/home/seanballais/Code/Projects/SAElections/venv/local/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response    
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)    
File "/home/seanballais/Code/Projects/SAElections/SAElections/fb_auth/views.py" in login    
  6.     return render(request, 'login.html')    
File "/home/seanballais/Code/Projects/SAElections/venv/local/lib/python3.4/site-packages/django/shortcuts.py" in render    
  67.             template_name, context, request=request, using=using)    
File "/home/seanballais/Code/Projects/SAElections/venv/local/lib/python3.4/site-packages/django/template/loader.py" in render_to_string    
  98.             template = get_template(template_name, using=using)    
File "/home/seanballais/Code/Projects/SAElections/venv/local/lib/python3.4/site-packages/django/template/loader.py" in get_template    
  29.     engines = _engine_list(using)    
File "/home/seanballais/Code/Projects/SAElections/venv/local/lib/python3.4/site-packages/django/template/loader.py" in _engine_list    
  144.     return engines.all() if using is None else [engines[using]]    
File "/home/seanballais/Code/Projects/SAElections/venv/local/lib/python3.4/site-packages/django/template/utils.py" in all    
  108.         return [self[alias] for alias in self]    
File "/home/seanballais/Code/Projects/SAElections/venv/local/lib/python3.4/site-packages/django/template/utils.py" in __iter__    
  105.         return iter(self.templates)    
File "/home/seanballais/Code/Projects/SAElections/venv/local/lib/python3.4/site-packages/django/utils/functional.py" in __get__    
  60.         res = instance.__dict__[self.name] = self.func(instance)    
File "/home/seanballais/Code/Projects/SAElections/venv/local/lib/python3.4/site-packages/django/template/utils.py" in templates    
  54.             tpl = tpl.copy()            

Exception Type: AttributeError at /    
Exception Value: 'str' object has no attribute 'copy'    
Run Code Online (Sandbox Code Playgroud)

编辑:添加在我的urls.py和追溯.

我希望这有帮助.任何帮助将不胜感激.谢谢!:)

dan*_*era 7

您应确保设置上的TEMPLATES是一个列表.

引用django文档:

TEMPLATES

Django 1.8中的新功能.默认:: [](空列表)

包含与Django一起使用的所有模板引擎的设置的列表.列表中的每个项目都是包含单个引擎选项的字典.

以下面的代码为例或指南.

TEMPLATES = [    
        {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',   
            'DIRS': [os.path.join(BASE_DIR, '<enter here your custom templates directory')], # For those who wants to have a custom place for templates in their Django apps/projects.
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
Run Code Online (Sandbox Code Playgroud)

编辑:添加一个例子,以防万一.