... hive/" , views . archive , name = "news-archive" ) URL を逆引きするために、以下の方法を使用できます: # using the named URL reverse ( "news-archive" ) # passing a callable object # (This is discouraged because you can't reverse namespaced views this way. ... ) from news import views reverse ( views . archive ) URLが引数を受け入れる場合は、 args にそれらを渡すことができます。例えば: from django.urls import rever ... se def myview ( request ): return HttpResponseRedirect ( reverse ( "arch-summary" , args = [ 1945 ])) kwargs を args の代わりに渡すこともできます。例えば: >>> reverse ( "admin:app_list" , ... ... sing reverse() Django's URL handling is based on a mapping of regex patterns (representing the URLs) to callable views, and Django's ow ... ted URL against those patterns to determine the appropriate view to invoke. Django also provides a convenience function -- reverse() -- which performs this process in the opposite direction. The reverse() function takes information about a view and retu ... rns a URL which would invoke that view. Use of reverse() is encouraged for application developers, as the output of reverse() is always based on the current URL patterns, meanin ... ... ted URL against those patterns to determine the appropriate view to invoke. Django also provides a convenience function -- reverse() -- which performs this process in the opposite direction. The reverse() function takes information about a view and retu ... rns a URL which would invoke that view. Use of reverse() is encouraged for application developers, as the output of reverse() is always based on the current URL patterns, meanin ... g developers do not need to change other code when making changes to URLs. One argument signature for reverse() is to pass a dotted Python path to the desired view. In this situation, Django will import the module indicated by that ... ... ted URL against those patterns to determine the appropriate view to invoke. Django also provides a convenience function -- reverse() -- which performs this process in the opposite direction. The reverse() function takes information about a view and retu ... rns a URL which would invoke that view. Use of reverse() is encouraged for application developers, as the output of reverse() is always based on the current URL patterns, meanin ... g developers do not need to change other code when making changes to URLs. One argument signature for reverse() is to pass a dotted Python path to the desired view. In this situation, Django will import the module indicated by that ... ... 指定したモデルの name という名前の制約を新たな constraint に置き換えます。 特別なオペレーション RunSQL class RunSQL ( sql , reverse_sql = None , state_operations = None , hints = None , elidable = False ) [ソース] データベース上で任意の SQL を実行できるよ ... うにします。Django が直接サポートしていない、データベースバックエンドのより高度な機能に便利です。 sql と reverse_sql があれば、データベースで実行する SQL の文字列を指定します。ほとんどのデータベースバックエンド (PostgreSQL 以外) では、 ... )]) クエリにパーセント文字リテラルを含ませたい場合、パラメータを渡していればパーセント文字を二重に記述する必要があります。 reverse_sql クエリはマイグレーションを元に戻す際に実行されます。これらのクエリは sql クエリで実行された内容を元に戻します。たとえば ... ... figured, and the appropriate header is set on the request, for both HTTP and HTTPS requests. If you deploy Django behind a reverse-proxy that forwards HTTP requests, and that connects to Django via HTTPS, be sure to verify that your application correctl ... ... figured, and the appropriate header is set on the request, for both HTTP and HTTPS requests. If you deploy Django behind a reverse-proxy that forwards HTTP requests, and that connects to Django via HTTPS, be sure to verify that your application correctl ... ... ting via HTTPS When deployed behind a reverse-proxy connecting to Django via HTTPS, django.http.HttpRequest.scheme would incorrectly detect client requests made via HTT ... figured, and the appropriate header is set on the request, for both HTTP and HTTPS requests. If you deploy Django behind a reverse-proxy that forwards HTTP requests, and that connects to Django via HTTPS, be sure to verify that your application correctl ... ... irst we need to add get_absolute_url() to our Author class: models.py from django.db import models from django.urls import reverse class Author ( models . Model ): name = models . CharField ( max_length = 200 ) def get_absolute_url ( self ): return reve ... ラスベースのビューのみを設定している点が重要です; 自分自身でロジックを書く必要はありません: views.py from django.urls import reverse_lazy from django.views.generic.edit import CreateView , DeleteView , UpdateView from myapp.models import Author class Auth ... iew ( UpdateView ): model = Author fields = [ "name" ] class AuthorDeleteView ( DeleteView ): model = Author success_url = reverse_lazy ( "author-list" ) 注釈 ファイルがインポートされるときに urls は読み込まれないので、 reverse_lazy() を reverse() の代わ ... ... r. >>> response . status_code 404 >>> # on the other hand we should expect to find something at '/polls/' >>> # we'll use 'reverse()' rather than a hardcoded URL >>> from django.urls import reverse >>> response = client . get ( reverse ( "polls:index" ) ... ションに基づいてテストを作成しましょう。 まず、 polls/tests.py に次の行を追加します。 polls/tests.py from django.urls import reverse そして、question を簡単に作れるようにするショートカット関数と、新しいテストクラスを作ります。 polls/tests.py def create_qu ... o_questions ( self ): """ If no questions exist, an appropriate message is displayed. """ response = self . client . get ( reverse ( "polls:index" )) self . assertEqual ( response . status_code , 200 ) self . assertContains ( response , "No polls are av ... 2026年10月08日