... class View 属性 (とオプションのアクセサ): http_method_names メソッド as_view() dispatch() head() http_method_not_allowed() setup() TemplateView class TemplateView 属性 (とオプションのアクセサ): content_type extra_context http_method_names response_cla ... ate_names() ] メソッド as_view() dispatch() get() get_context_data() head() http_method_not_allowed() render_to_response() setup() RedirectView class RedirectView 属性 (とオプションのアクセサ): http_method_names pattern_name permanent query_string url ... get_redirect_url() ] メソッド as_view() delete() dispatch() get() head() http_method_not_allowed() options() post() put() setup() 詳細ビュー DetailView class DetailView 属性 (とオプションのアクセサ): content_type context_object_name [ get_context_obj ... ... r from django.test import RequestFactory , TestCase from .views import MyView , my_view class SimpleTest ( TestCase ): def setUp ( self ): # Every test needs access to the request factory. self . factory = RequestFactory () self . user = User . object ... クラスベースのビューをテストする リクエスト/レスポンスサイクルの外でクラスベースのビューをテストするには、インスタンス化後に setup() を呼び出して、正しく設定されていることを確認する必要があります。 たとえば、以下のようなクラスベースのビューを想定します: ... super () . get_context_data ( ** kwargs ) get_context_data() メソッドを直接テストするには、まずビューをインスタンス化して setup() に request を渡します: tests.py from django.test import RequestFactory , TestCase from .views import HomeView class Home ... ... E のどちらか片方だけを使ってください。両方使うのも、両方使わないのもいけません。 スタンドアロンで Django を使うには django.setup() を呼び出す必要がある Django のコンポーネントを "スタンドアロン" で使う場合、たとえば、 Django テンプレートを読み込んでレ ... 必要なステップがあります。 After you've either set DJANGO_SETTINGS_MODULE or called configure() , you'll need to call django.setup() to load your settings and populate Django's application registry. For example: import django from django.conf import set ... tings from myapp import myapp_defaults settings . configure ( default_settings = myapp_defaults , DEBUG = True ) django . setup () # Now this script or any imported module can use any part of Django it needs. from myapp import models django.setup() を ... ... 承します。厳密にはジェネリックビューではないので、 django.views からインポートすることもできます。 メソッドのフローチャート setup() dispatch() http_method_not_allowed() options() Example views.py : from django.http import HttpResponse from django.views ... れたビューは、 view_class と view_initkwargs 属性を持っています。 リクエスト/レスポンスサイクル中にビューが呼び出されると、 setup() メソッドは HttpRequest をビューの request 属性に割り当て、 URLパターンからキャプチャされた位置引数および/またはキーワード ... async def ) と同期ハンドラ ( def ) の両方が1つのビュークラスで定義されている場合、 ImproperlyConfigured 例外が発生します。 setup ( request , * args , ** kwargs ) dispatch() の前に、ビューの初期化のための重要な処理を実行します。 ビューの request 属性に ... ... etail.BaseDetailView django.views.generic.detail.SingleObjectMixin django.views.generic.base.View メソッドのフローチャート setup() dispatch() http_method_not_allowed() get_template_names() get_slug_field() get_queryset() get_object() get_context_objec ... ic.list.BaseListView django.views.generic.list.MultipleObjectMixin django.views.generic.base.View メソッドのフローチャート setup() dispatch() http_method_not_allowed() get_template_names() get_queryset() get_context_object_name() get_context_data() ge ... ... ト環境をセットアップすることです。 / $ python manage.py shell ...\> py manage.py shell >>> from django.test.utils import setup_test_environment >>> setup_test_environment () setup_test_environment() は、テンプレートのレンダラーをインストールします。 ... t address; if you instead see an >>> # "Invalid HTTP_HOST header" error and a 400 response, you probably >>> # omitted the setup_test_environment() call described earlier. >>> response . status_code 404 >>> # on the other hand we should expect to find ... ... st --debug-mode option to help troubleshoot test failures by setting the DEBUG setting to True . The new django.test.utils.setup_databases() (moved from django.test.runner ) and teardown_databases() functions make it easier to build custom test runner ... するようになりました。 保存した値を失わないように、 teardown_test_environment() を呼び出す前に 2 度めの呼び出しをした場合、 setup_test_environment() がエラーを投げるようになりました。 DjangoJSONEncoder (Django 1.0 でリネームされました) に対する、ドキュ ... 、 password_reset_done() 、 password_reset_confirm() 、 password_reset_complete() は非推奨となりました。 django.test.runner.setup_databases() が django.test.utils.setup_databases() に移動しました。旧来の場所は非推奨となります。 django.utils.text.format ... ... Cached template loaders are now correctly reloaded in development. テスト Objects assigned to class attributes in TestCase.setUpTestData() are now isolated for each test method. Such objects are now required to support creating deep copies with copy.d ... he test --no-faulthandler option. DiscoverRunner and the test management command can now track timings, including database setup and total run time. This can be enabled by using the test --timing option. Client now preserves the request query string w ... ior. See Django 3.2 の新機能 for more details. Instantiating an abstract model now raises TypeError . Keyword arguments to setup_databases() are now keyword-only. The undocumented django.utils.http.limited_parse_qsl() function is removed. Please use u ... ... 20257). Fixed a regression in django.contrib.gis in the Google Map output on Python 3 (#20773). Made DjangoTestSuiteRunner.setup_databases properly handle aliases for the default database (#19940) and prevented teardown_databases from attempting to te ... ... ixed a regression in Django 2.2.1 that caused a crash when migrating permissions for proxy models with a multiple database setup if the default entry was empty ( #31021 ). Fixed a data loss possibility in the select_for_update() . When using 'self' in ... 2026年10月08日