不开心的水煮鱼 · 使用JavaScript或Vue框架解决SV ...· 1 月前 · |
谦和的火龙果 · 查询和分析日志以及查看结果_日志服务(SLS ...· 4 月前 · |
英勇无比的玉米 · Weird behaviour of ...· 12 月前 · |
知识渊博的匕首 · NavigationView - ...· 1 年前 · |
我试着在这里用表格登录-
http://stackoverflow.com/questions/31576801/django-login-exception-value-unicode-object-is-not-callable#31576801
当我点击登录时,我得到了以下回溯-
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/datapi/core/views.py" in LoginRequest
47. return render_to_response('/',ctx,context_instance=RequestContext(request))
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts.py" in render_to_response
23. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in render_to_string
170. t = get_template(template_name, dirs)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in get_template
144. template, origin = find_template(template_name, dirs)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in find_template
136. raise TemplateDoesNotExist(name)
Exception Type: TemplateDoesNotExist at /login/
Exception Value: /
这是我的观点-
def LoginRequest(request):
if request.user.is_authenticated():
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
password = form.cleaned_data['password']
user = authenticate(email=email, password=password)
if user is not None:
login(request, user)
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
else:
return render_to_response('/', {'form': form}, context_instance=RequestContext(request))
else:
return render_to_response('/', {'form': form}, context_instance=RequestContext(request))
else:
form = LoginForm()
return render_to_response('/', {'form': form}, context_instance=RequestContext(request))
我只能想象模板不存在,因为它不是模板。我想要做的是让我的视图登录,然后返回到根url。
发布于 2015-07-23 02:40:04
您需要在
template_name
render_to_response
**
.中传递
您不是这样做的,而是传递一个**
url
**.**
render_to_response
的基本签名
render_to_response(template_name[, context][, context_instance][, content_type][, status][, dirs][, using])
这将使用给定的
template
字典呈现给定的
context
,并返回带有该已呈现文本的
HttpResponse
对象。
因此,以下声明不应是:
return render_to_response('/', {'form': form}, context_instance=RequestContext(request))
相反,应该是这样的:
return render_to_response('template_name_of_index_page', {'form': form}, context_instance=RequestContext(request))
发布于 2015-07-23 02:34:42
我不得不回到下面的观点-
def LoginRequest(request):
active = "index"
message = ""
if request.user.is_authenticated():
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
else:
if request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data['email']
password = form.cleaned_data['password']
user = authenticate(username=username,password=password)
if user is not None and user.is_active:
login(request,user)
return HttpResponseRedirect('/dashboard')