Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django 1.8:AttributeErrorat/:';str';对象没有属性';复印件';_Python_Django - Fatal编程技术网

Python Django 1.8:AttributeErrorat/:';str';对象没有属性';复印件';

Python Django 1.8:AttributeErrorat/:';str';对象没有属性';复印件';,python,django,Python,Django,我一直在试用Django 1.8.1。到目前为止,它一直很好,直到我测试它。当我转到Django提供文件的地址(localhost:8000)时,我得到了错误: 属性错误位于/: “str”对象没有“copy”属性 我在Django有一个名为fb_auth的应用程序。这是目录树。 /路径/到/项目/目录 | ---.gitignore | ---吴富计划 | ---吴富计划 ---fb_auth ---模板 --- 在回溯中,我可以从我的视图中看到这条高亮显示的线。 返回呈现(请求'l

我一直在试用Django 1.8.1。到目前为止,它一直很好,直到我测试它。当我转到Django提供文件的地址(
localhost:8000
)时,我得到了错误:

属性错误位于/:
“str”对象没有“copy”属性

我在Django有一个名为fb_auth的应用程序。这是目录树。

/路径/到/项目/目录
|
---.gitignore
|
---吴富计划
|
---吴富计划
---fb_auth
---模板
---

在回溯中,我可以从我的视图中看到这条高亮显示的线。

返回呈现(请求'login.html')

这是我的
视图。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('/')
下面是我的
url.py
(如果这有帮助):

这是我的
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 %} 
这是回溯:

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'    
编辑:添加到my
urls.py
和回溯中

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

您应该确保设置中有一个列表

引用django文件:

模板

在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',
            ],
        },
    },
]
模板=[
{
'BACKEND':'django.template.backends.django.DjangoTemplates',

'DIRS':[os.path.join(BASE_DIR,'你有一个回溯,你应该在这里发布。哦,是的,忘了包括回溯。现在就包括。检查设置。确保是一个列表。我已经这样做了,它工作了。我找到了解决方案。准备回答我自己的问题,以防其他人遇到此类错误消息。@SeanfrancisBallais,很好。我作为solut发布它。@SeanfrancisBallais,niceion.在OP确认我的问题评论是他们的解决方案后,我在这里发布了答案。开心点。哦,现在我看到了这个。很好。很抱歉之前的误解。你得到了+100赏金。:)非常感谢。嗯。别担心。你仍然会因为帮助我而获得+100赏金。根据StackOverflow的说法,我将在23小时内奖励赏金。不管怎样,我很乐意帮助你。问候。
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'    
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',
            ],
        },
    },
]