Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

n-tamaki1506
Copy link
Collaborator

@n-tamaki1506 n-tamaki1506 commented Aug 19, 2024

受講生の確認事項

  • 画面をブラウザで実際に開いてテスト要件の画面と機能の動作確認をした(動作が分からない場合講師からスクリーンショットの提出を求めることがあります)
  • 作成したモデルを全てDjango管理画面に登録した
  • テスト要件のテストを全て実装した
  • CI が全て通った

1次レビュアーの確認事項

@n-tamaki1506 n-tamaki1506 marked this pull request as ready for review August 19, 2024 14:58
# 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'),
Copy link
Contributor

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
Copy link
Contributor

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>
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コンテキストってテンプレート上で表示するために作成しているもので、
今回は user_profile.html でuserっていう変数使っていないのでこの行は不要です🙅‍♀️

Copy link
Contributor

@h-iwasaki083 h-iwasaki083 left a 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に飛ぶボタン

が表示されるようにしてみてください!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants