0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Djangoのエラー"TypeError: consume_points() missing 1 required positional argument: 'request'"で苦戦した話

Posted at

djangoのview.pyでリクエストからユーザーを取得して処理を実装しようとしていた際に
TypeError: consume_points() missing 1 required positional argument: 'request
に直面して時間を食ってしまったので備忘録を載せておきます。

原因(結論)

関数ベースビューで"self"を使ってユーザー情報を取得しようとしていたことが原因でした。
実際に、下記のような間違った書き方をしていました。


def proccess(self,request):
    if request.method == 'POST':
        user = self.request.user
        #以下省略

selfを使うのは、クラスビューベースで定義するときのようです。

解決策

selfを使わず、以下のように書けばエラーを回避できます


def proccess(request):
    if request.method == 'POST':
        user = request.user
        #以下省略
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?