ログインしたユーザーによって遷移先を変えたい
ログインしたユーザーによって遷移先を変えたい
Djangoでログイン機能を搭載し、ログイン後 ホーム画面に遷移するのですが、役職によって遷移先を変えたいと思って
実装していたのですが、うまくいきません。どうしたらいいのでしょうか、Google先生に聞いても例になるようなものがなく
困っています。
大まかな流れ
ログインページ > ログインする > ログインしたユーザーの役職は「役員」か「社員」か
役員だったら 役員用のホーム画面 社員だったら 社員用のホーム画面
ホーム画面はそれぞれのhtmlを用意しています。
ユーザー情報に役職が紐づいています。
login.html
{% extends "account/base.html" %}
{% block title %}ログイン{% endblock %}
{% block content %}
<div class="container">
<h1>ログイン</h1>
<p>{{message}}</p>
<form action="{% url 'login'%}" method="post">
{% csrf_token %}
{{ form.as_p }}
<p><input type="hidden" name="next" value="{{next}}"></p>
<p><input type="submit" value="ログイン"></p>
</form>
</div>
{% endblock %}
form.py
class LoginForm(AuthenticationForm):
class Meta:
model = SyainMaster
fields = ['email', 'password']
views.py
class HomeView(LoginRequiredMixin, TemplateView):
template_name = "account/Syainhome.html"
def get(self, request, **kwargs ):
post = self.request.user.post
#ユーザー情報に postレコードに 0,1,2(0:役員, 1:リーダー, 2:平社員) のデータが入っています。
if post == 0:
template_name = "account/Yakuinhome.html"
else:
template_name = "account/Syainhome.html"
return template_name
def get_context_data(self, **kwargs):
content = super().get_context_data(**kwargs)
content.update({
'MendanMaster':MendanMaster.objects.all(),
})
return content
class LiginView(LoginView):
"""ログインページ"""
form_class = forms.LoginForm
template_name = "account/login.html"
エラー文
Internal Server Error: /home/
Traceback (most recent call last):
File "C:\Users\*****\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
File "C:\Users\*****\django\utils\deprecation.py", line 138, in __call__
response = self.process_response(request, response)
File "C:\Users\*****\django\middleware\clickjacking.py", line 27, in process_response
if response.get("X-Frame-Options") is not None:
AttributeError: 'str' object has no attribute 'get'
0 likes