realpython / realpython/materials
[Patch] Dtwitter crash if user not logged
まだ誰も着手していません。
- 主要言語
- Jupyter Notebook
- スター
- 5.2k
- フォーク
- 5.3k
- 平均マージ
- 4日 10時間
- マージ済み PR(30日)
- 10
説明
ℹ️ Please note that the best way to get support for Real Python courses & articles is to join one of our weekly Office Hours calls or in the RP Community Slack.
You can report issues and problems here, but we typically won't be able to provide 1:1 support outside the channels listed above.
Describe the bug
If you get from part-4 the source final and load in the browser you get:
Traceback (most recent call last):
File "/var/www/dtwitter/myvenv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/var/www/dtwitter/myvenv/lib/python3.11/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/www/dtwitter/dwitter/views.py", line 17, in dashboard
user__profile__in=request.user.profile.follows.all()
^^^^^^^^^^^^^^^^^^^^
File "/var/www/dtwitter/myvenv/lib/python3.11/site-packages/django/utils/functional.py", line 247, in inner
return func(self._wrapped, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'AnonymousUser' object has no attribute 'profile'
Fix
The first lines of the file https://github.com/realpython/materials/blob/master/dwitter-part-4/source_code_final/dwitter/views.py#L7 should be:
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from .forms import DweetForm
from .models import Dweet, Profile
@login_required(login_url='/admin/')
def dashboard(request):
form = DweetForm(request.POST or None)
In this way automatically if the user is not logged get redirect to the admin for login, maybe there are better ways as it is just a prototype, but a prototype shouldn't crash.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
dwitter-part-4/source_code_final/dwitter/views.py を開き、request.user.profile へのアクセス付近にある dashboard view を調べます。認証されていないブラウザーリクエストを再現し、AnonymousUser 例外を発生させるのではなく、管理者ログインにリダイレクトされることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- django, python
- 領域
- authentication, backend
- issue の種類
- バグ
- 難易度
- 1/5
- 見積もり時間
- 1時間未満
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100