로그인하여 관리자 사이트의 로그인 양식과 "대시 보드"로 리디렉션하고 "관리자 패널"로 리디렉션하는 방법어떻게 장고에서 두 가지 다른 로그인 양식을 만들 수 있습니까?
내가 찾고 있었고 ModelBackend 이것을 참조로 찾았지만 그것을 어떻게하는지 명확하게하지 않습니다. https://docs.djangoproject.com/en/1.8/topics/auth/customizing/
로그인하여 관리자 사이트의 로그인 양식과 "대시 보드"로 리디렉션하고 "관리자 패널"로 리디렉션하는 방법어떻게 장고에서 두 가지 다른 로그인 양식을 만들 수 있습니까?
내가 찾고 있었고 ModelBackend 이것을 참조로 찾았지만 그것을 어떻게하는지 명확하게하지 않습니다. https://docs.djangoproject.com/en/1.8/topics/auth/customizing/
두 개의 로그인보기가 필요하다는 것을 알고 있습니다. 앱에서 예를 들어, 2 뷰를 생성 views.py의 :
def loginDashboard(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/')
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
account = authenticate(username=username, password=password)
if account is not None:
login(request, account)
#here is redirecting to dashboard
return HttpResponseRedirect('/dashboard/')
else:
return render(request, 'profiles/login.html', context)
else:
return render(request, 'profiles/login.html', context)
else:
form = LoginForm()
context = {'form':form}
return render(request, 'profiles/login.html', context)
def loginAdminPanel(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/')
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
account = authenticate(username=username, password=password)
if account is not None:
login(request, account)
#here is redirecting to admin panel
return HttpResponseRedirect('/adminpanel/')
else:
return render(request, 'profiles/login.html', context)
else:
return render(request, 'profiles/login.html', context)
else:
form = LoginForm()
context = {'form':form}
return render(request, 'profiles/login.html', context)
그리고 당신의 urls.py :이 경우
url(r'^login-dash/$', views.loginDashboard),
url(r'^login-admin/$', views.loginAdminPanel),
두 로그인 페이지 (example.com/login-dash
및 example.com/login-admin
)
이를 내 form.py :
class LoginForm(forms.Form):
username = forms.CharField(label=(u'Username'))
password = forms.CharField(label=(u'Pasword'), widget=forms.PasswordInput(render_value=False))
희망이 있습니다.
나는 이것을 시험해보고있다. –
두 개의보기를 만들 수 있습니다. 첫 번째 패널은 'Dashboard'로 리디렉션되고 두 번째 패널은 '관리자 패널'로 리디렉션됩니다. –
로그인 폼은 Django 기본 로그인 페이지를 사용하고 로그인에 성공하면 다른 착륙을 유도해야합니까? –
하지만 어떻게 할 수 있습니까? 나는 찾고 있었고 ModelBackend 만 찾았습니다 :/그리고 너보다 훨씬! –