... d like other expressions . 条件式クラス ¶ このページの例では、以下のモデルを使用します: from django.db import models class Client ( models . Model ): REGULAR = "R" GOLD = "G" PLATINUM = "P" ACCOUNT_TYPE_CHOICES = { REGULAR : "Regular" , GOLD : "Gold" , ... F , Q , When >>> # String arguments refer to fields; the following two examples are equivalent: >>> When ( account_type = Client . GOLD , then = "name" ) >>> When ( account_type = Client . GOLD , then = F ( "name" )) >>> # You can use field lookups in ... created using boolean expressions. >>> from django.db.models import Exists , OuterRef >>> non_unique_account_type = ( ... Client . objects . filter ( ... account_type = OuterRef ( "account_type" ), ... ) ... . exclude ( pk = OuterRef ( "pk" )) ... . v ... ... d like other expressions . 条件式クラス ¶ このページの例では、以下のモデルを使用します: from django.db import models class Client ( models . Model ): REGULAR = "R" GOLD = "G" PLATINUM = "P" ACCOUNT_TYPE_CHOICES = { REGULAR : "Regular" , GOLD : "Gold" , ... F , Q , When >>> # String arguments refer to fields; the following two examples are equivalent: >>> When ( account_type = Client . GOLD , then = "name" ) >>> When ( account_type = Client . GOLD , then = F ( "name" )) >>> # You can use field lookups in ... created using boolean expressions. >>> from django.db.models import Exists , OuterRef >>> non_unique_account_type = ( ... Client . objects . filter ( ... account_type = OuterRef ( "account_type" ), ... ) ... . exclude ( pk = OuterRef ( "pk" )) ... . v ... ... るには、これらすべてのタイプのテストを組み合わせて行うべきです。 概要と簡単な例 ¶ テストクライアントを使うには、 django.test.Client からインスタンスを作り、次のようにウェブページを取得します。 >>> from django.test import Client >>> c = Client () >>> resp ... 0 >>> response = c . get ( "/customer/details/" ) >>> response . content b'<!DOCTYPE html...' この例が示唆しているように、 Client のインスタンスは、Python のインタラクティブなインタプリタ上のセッションからでも作ることができます。 テストクライアントの動 ... ことができます。これには、クライアントを作る時に次のように enforce_csrf_checks 引数を渡します。 >>> from django.test import Client >>> csrf_client = Client ( enforce_csrf_checks = True ) リクエストの作成 ¶ リクエストの作成には、 django.test.Client クラス ... ... るには、これらすべてのタイプのテストを組み合わせて行うべきです。 概要と簡単な例 ¶ テストクライアントを使うには、 django.test.Client からインスタンスを作り、次のようにウェブページを取得します。 >>> from django.test import Client >>> c = Client () >>> resp ... 0 >>> response = c . get ( "/customer/details/" ) >>> response . content b'<!DOCTYPE html...' この例が示唆しているように、 Client のインスタンスは、Python のインタラクティブなインタプリタ上のセッションからでも作ることができます。 テストクライアントの動 ... ことができます。これには、クライアントを作る時に次のように enforce_csrf_checks 引数を渡します。 >>> from django.test import Client >>> csrf_client = Client ( enforce_csrf_checks = True ) リクエストの作成 ¶ リクエストの作成には、 django.test.Client クラス ... ... fix that forms part of the 1.2.2 release, it was necessary to add a feature -- the enforce_csrf_checks flag -- to the test client . This flag forces the test client to perform full CSRF checks on forms. The default behavior of the test client hasn't ch ... anged, but if you want to do CSRF checks with the test client, it is now possible to do so. 目次 Django 1.2.2 リリースノート One new feature 前のトピックへ Django 1.2.3 リリースノート ... 次のトピックへ Django 1.2.1 リリースノート 関連キーワード client release features checks リリースノート backwards feature forms flag second bugfix series improving stability performance c ... ... fix that forms part of the 1.2.2 release, it was necessary to add a feature -- the enforce_csrf_checks flag -- to the test client . This flag forces the test client to perform full CSRF checks on forms. The default behavior of the test client hasn't ch ... anged, but if you want to do CSRF checks with the test client, it is now possible to do so. 目次 Django 1.2.2 リリースノート One new feature 前のトピックへ Django 1.2.3 リリースノート ... 次のトピックへ Django 1.2.1 リリースノート 関連キーワード Django test client release but new features checks リリースノート backwards feature forms flag second bugfix series improving stability perfo ... ... う。 初めに何かを修正する前に、使用できるツールについて見ておきましょう。 Django テストクライアント ¶ Django provides a test Client to simulate a user interacting with the code at the view level. We can use it in tests.py or even in the shell . もう一度 ... 中では、 django.test.TestCase クラス自体がクライアントを持っているため、インポートは不要です)。 >>> from django.test import Client >>> # create an instance of the client for our use >>> client = Client () さて、これでクライアントに仕事を頼む準備ができま ... した。 >>> # get a response from '/' >>> response = client . get ( "/" ) Not Found: / >>> # we should expect a 404 from that address; if you instead see an >>> # "Invalid HTTP_HOST ... ... う。 初めに何かを修正する前に、使用できるツールについて見ておきましょう。 Django テストクライアント ¶ Django provides a test Client to simulate a user interacting with the code at the view level. We can use it in tests.py or even in the shell . もう一度 ... 中では、 django.test.TestCase クラス自体がクライアントを持っているため、インポートは不要です)。 >>> from django.test import Client >>> # create an instance of the client for our use >>> client = Client () さて、これでクライアントに仕事を頼む準備ができま ... した。 >>> # get a response from '/' >>> response = client . get ( "/" ) Not Found: / >>> # we should expect a 404 from that address; if you instead see an >>> # "Invalid HTTP_HOST ... ... umentation for TestCase and TransactionTestCase for a full description, and some important notes on database support. Test client improvements ¶ A couple of small -- but highly useful -- improvements have been made to the test client: The test Client n ... ow can automatically follow redirects with the follow argument to Client.get() and Client.post() . This makes testing views that issue redirects simpler. It's now easier to get at the template co ... ntext in the response returned the test client: you'll simply access the context as request.context[key] . The old way, which treats request.context as a list of context ... ... umentation for TestCase and TransactionTestCase for a full description, and some important notes on database support. Test client improvements ¶ A couple of small -- but highly useful -- improvements have been made to the test client: The test Client n ... ow can automatically follow redirects with the follow argument to Client.get() and Client.post() . This makes testing views that issue redirects simpler. It's now easier to get at the template co ... ntext in the response returned the test client: you'll simply access the context as request.context[key] . The old way, which treats request.context as a list of context ... 2026年10月08日