-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ログイン・ログアウト機能の実装 #2
base: main
Are you sure you want to change the base?
Conversation
# path('login/', auth_views.LoginView.as_view(), name='login'), | ||
# path('logout/', auth_views.LogoutView.as_view(), name='logout'), | ||
path("login/", LoginView.as_view(template_name="accounts/login.html"), name="login"), | ||
path("logout/", LogoutView.as_view(), name="logout"), | ||
# path('<str:username>/', views.UserProfileView.as_view(), name='user_profile'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここのコメントアウト外してあげましょう!今のままではプロフィールページ見られないはず
from django.contrib.auth import authenticate, login | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
from django.contrib.auth.models import User |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここで取って来ているUserモデルは、Djangoでデフォルトで提供されている組み込みのモデルです。
今回持ってきたいのはサインアップ機能の時にmodels.pyに書いて作成したものなので、インポート元を修正しましょう!今の状態だとユーザーのデータ持ってこられていなくてページ開いたときにエラー起きちゃってる🫠
{% block title %}User Profile{% endblock %} | ||
|
||
{% block content %} | ||
<p>{(username)}</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コンテキストを取ってくるには {{ username }} って {{ }} で囲ってあげてください!
context = super().get_context_data(**kwargs) | ||
username = self.kwargs.get("username") | ||
user = User.objects.get(username=username) | ||
context["user"] = user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コンテキストってテンプレート上で表示するために作成しているもので、
今回は user_profile.html でuserっていう変数使っていないのでこの行は不要です🙅♀️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あと、base.htmlで今Twitter CloneとSign upボタンが表示されているところで、
- ユーザーがログインしている→ログアウトボタンとホームボタン
- ユーザーがログインしていない→ログインボタンとサインアップボタンとTwitter Cloneに飛ぶボタン
が表示されるようにしてみてください!
受講生の確認事項
1次レビュアーの確認事項