我是Django框架的新手,我正在尝试执行Django身份验证视图,但我一直在收到此错误
C:\Users\Harsley\bookmarks>python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
March 21, 2017 - 21:11:56
Django version 1.10.6, using settings 'bookmarks.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Internal Server Error: /
Traceback (most recent call last):
File "C:\Users\Harsley\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 42, in inner
response = get_response(request)
File "C:\Users\Harsley\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 138, in __call__
response = self.process_response(request, response)
File "C:\Users\Harsley\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\middleware\clickjacking.py", line 32, in process_response
if response.get('X-Frame-Options') is not None:
AttributeError: 'tuple' object has no attribute 'get'
[21/Mar/2017 21:11:58] "GET / HTTP/1.1" 500 57044
这是我的url.py文件
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from . import views
urlpatterns = [
url(r'^login$', auth_views.login, name='login'),
url(r'^logout$', auth_views.logout, name='logout'),
url(r'^logout_then_login$', auth_views.logout_then_login, `name='logout_then_login'),`
url(r'^$', views.dashboard, name='dashboard'),
]
以下是我的观点
from django.contrib.auth.decorators import login_required
@login_required()
def dashboard(request):
return (request, 'dashboard.html', {'section': 'dashboard'})
答案 0 :(得分:4)
这是错误的:
return (request, 'dashboard.html', {'section': 'dashboard'})
您将返回tuple
,您必须返回Response。
您可以使用render
- 快捷方式:
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
@login_required()
def dashboard(request):
return render(request, 'dashboard.html', {'section': 'dashboard'})