を必要としないようにDjangoの残りのフレームワークのビューセットでメソッドを設定します。このcreate
メソッドは認証を必要としないとはどうして簡単に言えますか? トークンを使用して認証を実装した後で知っているように、すべてのリクエストのヘッダーにはToken
が含まれていて、必要のないリクエストでは403エラーが発生します。は、どのように私は以下のように<a href="http://www.django-rest-framework.org/api-guide/viewsets/" rel="nofollow noreferrer">viewset</a>を持っている認証
1
A
答えて
1
DRFの問題追跡ツールでは、this issueとなります。最も良い方法は、カスタムアクセス許可クラスを作成することです。ビューオブジェクトにはaction
という属性があり、これを使用して、ViewSetの各サブアクションに応じて行う操作を変更できます。
class IsCreationOrIsAuthenticated(permissions.BasePermission):
def has_permission(self, request, view):
if not request.user.is_authenticated():
if view.action == 'create':
return True
else:
return False
else:
return True
からより詳細一方(リンクが壊れているか変更された場合のコードは、ちょうどリンクしないのSO方針に沿ってここにコピーされた。)
class AnonCreateAndUpdateOwnerOnly(permissions.BasePermission):
"""
Custom permission:
- allow anonymous POST
- allow authenticated GET and PUT on *own* record
- allow all actions for staff
"""
def has_permission(self, request, view):
return view.action == 'create' or request.user and request.user.is_authenticated
def has_object_permission(self, request, view, obj):
return view.action in ['retrieve', 'update', 'partial_update'] and obj.id == request.user.id or request.user.is_staff
class ListAdminOnly(permissions.BasePermission):
"""
Custom permission to only allow access to lists for admins
"""
def has_permission(self, request, view):
return view.action != 'list' or request.user and request.user.is_staff
を
関連する問題
- 1. ジェンキンスパイプラインのビルドは、私は以下のように<a href="https://jenkins.io/doc/book/pipeline/syntax/" rel="nofollow noreferrer">declarative</a>パイプラインステージを持っている
- 2. PHP LDAP - のmemberOfを表示私は(<a href="https://samjlevy.com/archives/" rel="nofollow">https://samjlevy.com/archives/</a>)から、以下のようなスクリプトを持っているグループ
- 3. TimestampBehaviorは、私は<a href="http://www.yiiframework.com/doc-2.0/yii-behaviors-timestampbehavior.html" rel="nofollow noreferrer">TimestampBehaviour</a>と以下のクラスを持っているので、失敗の検証
- 4. は、どのように私は<a href="http://controlsjs.com/" rel="nofollow">Hello demo</a></p> <p>をしようとしていた
- 5. 私は<a href="https://omeka.org/" rel="nofollow noreferrer">Omeka</a>の私の元のインスタンスを持つリモートサーバー持って
- 6. フォワードドメインの後に302リダイレクトを以下、以降は<a href="http://example.com" rel="nofollow">http://example.com</a>にループを
- 7. どのようにあなたが以下のように<a href="http://www.chartjs.org/docs/latest/configuration/legend.html" rel="nofollow noreferrer">generate HTML legend in Chart.js</a>できChart.js
- 8. の画像は、私はgithubのページに<a href="http://calebbertrand.github.io" rel="nofollow noreferrer">website</a>を持って
- 9. は、私は<a href="https://redom.js.org" rel="nofollow noreferrer">redom</a>ライブラリをインポートしようとしています
- 10. は、どのように私は<a href="http://www.firebase.com/tutorial/" rel="nofollow">the firebase tutorial</a>をしようとしている
- 11. $私は以下のように<a href="https://github.com/sebastianha/angular-bootstrap-checkbox" rel="nofollow">angular-bootstrap-checkbox</a>を使用しています
- 12. は、どのように私はvue.js <a href="https://github.com/vuejs/vue-hackernews-2.0" rel="nofollow">boilerplate code</a>を強化しようとしていた
- 13. どのように私は<a href="https://datatables.net/reference/option/language.loadingRecords" rel="nofollow">this</a>よう<code>loadingRecords</code>を設定し、ネイティブのDataTableに
- 14. どのように私は以下のようにメソッドを持って
- 15. は、私は以下のようにサービスクラスを持っているアクション<T>
- 16. 私は以下のようにファイルを持っているパターン
- 17. 私は以下のようにデータフレーム持っているのPython
- 18. は、私は(<a href="http://jsonlint.com/" rel="nofollow">http://jsonlint.com/</a>からテスト)以下の有効なJSONデータを持っているJSON
- 19. Androidはどのように<a href="https://developer.android.com/studio/publish/versioning.html" rel="nofollow">this</a>ページで
- 20. Highchartsは、次のよう<a href="http://api.highcharts.com/highcharts/yAxis.minPadding" rel="nofollow">docs</a>によれば、軸パディング
- 21. 式のテンプレートは次のように私は<a href="https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern" rel="nofollow">CRTP</a>基本クラスを持って打ち鳴らす
- 22. はどのように<a href="https://developer.android.com/reference/android/media/MediaPlayer.html#getDuration()" rel="nofollow noreferrer">MediaPlayer</a>からアンドロイド
- 23. 私は、XML以下のように持っているXSLT
- 24. 私が欲しいもの</p> <p><a href="https://i.stack.imgur.com/8TH6m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8TH6m.png" alt="enter image description here"></a></p> <p>以下のように私は、グラフのネットワークを持っているCYPHER(のNeo4j)
- 25. Djangoは以下のようにどのように私は私が辞書のリストを持っている
- 26. は、どのように私は以下のクラスを持っているシーケンス
- 27. は、どのように私は以下のクラスを持っている
- 28. は、どのように私は以下のクラスを持っているナビゲーションプロパティ
- 29. 私はこのようにそれを実装<a href="http://jqueryui.com/autocomplete/" rel="nofollow noreferrer">http://jqueryui.com/autocomplete/</a></p> <p>からウィジェットを持っ
- 30. 私は大体<a href="http://codepen.io/ierik/pen/ZpaZKz" rel="nofollow">this CodePen</a>のように見えるページレイアウトをコーディングしようとしている列が