当我运行我的服务器时,我收到一条类型错误消息,告诉我:
我的视图必须是可调用的或列表/元组
从我收集的django版本不同而且为了清楚起见,我使用的是django最新版本......无论如何这里是我的项目的views.py和urls.py:
url.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^login/$',
'django.contrib.auth.views.login',name='login'),
url(r'^logout/$',
'django.contrib.auth.views.logout',name='logout'),
url(r'^logout-then-login/$',
'django.contrib.auth.views.logout_then_login',name='logout_then_login'),
]
views.py
from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth import authenticate, login
from .forms import LoginForm
from django.contrib.auth.decorators import login_required
def user_login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
user = authenticate(username=cd['username'],password=cd['password'])
if user is not None:
if user.is_active:
login(request, user)
return HttpResponse('Authenticated successfully')
else:
return HttpResponse('Disabled account')
else:
return HttpResponse('Invalid login')
else:
form = LoginForm()
return render(request, 'account/login.html', {'form': form})
@login_required
def dashboard(request):
return render(request,
'account/dashboard.html',{'section': 'dashboard'})
答案 0 :(得分:0)
尝试将您的网址格式更改为以下内容:
urlpatterns = [
url(r'^login/$',
django.contrib.auth.views.login,name='login'),
url(r'^logout/$',
django.contrib.auth.views.logout,name='logout'),
url(r'^logout-then-login/$',
django.contrib.auth.views.logout_then_login,name='logout_then_login'),
]
从docs for latest django版本来看,视图是功能而非字符串。