2 回答
![?](http://img1.sycdn.imooc.com/533e4d5b0001d57502200203-100-100.jpg)
TA贡献1850条经验 获得超11个赞
请执行以下操作:
def login_user(request): # we don't do camel-casing
# I don't know your exact use case, but having this in the view seems wrong..
schema_list1 = ['pierre']
schema_lsit2 = ['itoiz']
# This will be an empty "{}" if it's not a POST, meaning, you don't need the
# extra if, it will work in both cases
form = AuthenticationForm(data=request.POST)
if request.method == 'POST':
dbschema, _, _ = request.get_host().partition('.')
if form.is_valid():
user = form.get_user()
login(request, user)
if dbschema in schema_list1:
print('yes')
redirect = '/upload.html'
return HttpResponseRedirect(redirect)
elif dbschema in schema_list2:
print('yes')
redirect = '/dash2.html'
return HttpResponseRedirect(redirect)
else:
raise Exception('HANDLE THIS!!!')
context = {
'form': form,
}
return render(request, 'loginUser.html', context)
![?](http://img1.sycdn.imooc.com/5333a1d100010c2602000200-100-100.jpg)
TA贡献1813条经验 获得超2个赞
当您提交表单时 - 您可能会向“loginUser”发送不带参数的请求。
另一件事是,您可能不需要 URL 作为参数,您可以简单地从请求中获取它:
request.build_absolute_uri()
添加回答
举报