... ural use of URLconfs. For example, this URLconf: from django.conf.urls.defaults import * urlpatterns = patterns ( "" , ( "^myview/$" , "mysite.myapp.views.myview" )) can now be rewritten as: from django.conf.urls.defaults import * from mysite.myapp.vie ... ws import myview urlpatterns = patterns ( "" , ( "^myview/$" , myview )) One useful application of this can be seen when using decorators; ... m mysite.myapp.models import MyModel info = { "queryset" : MyModel . objects . all (), } urlpatterns = patterns ( "" , ( "^myview/$" , login_required ( object_list ), info )) Note that both syntaxes (strings and callables) are valid, and will continue ... ... ural use of URLconfs. For example, this URLconf: from django.conf.urls.defaults import * urlpatterns = patterns ( "" , ( "^myview/$" , "mysite.myapp.views.myview" )) can now be rewritten as: from django.conf.urls.defaults import * from mysite.myapp.vie ... ws import myview urlpatterns = patterns ( "" , ( "^myview/$" , myview )) One useful application of this can be seen when using decorators; ... m mysite.myapp.models import MyModel info = { "queryset" : MyModel . objects . all (), } urlpatterns = patterns ( "" , ( "^myview/$" , login_required ( object_list ), info )) Note that both syntaxes (strings and callables) are valid, and will continue ... ... arefully. One deprecated feature worth noting is the shift to "new-style" url tag. Prior to Django 1.3, syntax like {% url myview %} was interpreted incorrectly (Django considered "myview" to be a literal name of a view, not a template variable named m ... yview ). Django 1.3 and above introduced the {% load url from future %} syntax to bring in the corrected behavior where myview was seen as a variable. The upshot of this is that if you are not using {% load url from future %} in your templates, you' ... ll need to change tags like {% url myview %} to {% url "myview" %} . If you were using {% load url from future %} you can simply remove that line under Django 1.5 P ... ... arefully. One deprecated feature worth noting is the shift to "new-style" url tag. Prior to Django 1.3, syntax like {% url myview %} was interpreted incorrectly (Django considered "myview" to be a literal name of a view, not a template variable named m ... yview ). Django 1.3 and above introduced the {% load url from future %} syntax to bring in the corrected behavior where myview was seen as a variable. The upshot of this is that if you are not using {% load url from future %} in your templates, you' ... ll need to change tags like {% url myview %} to {% url "myview" %} . If you were using {% load url from future %} you can simply remove that line under Django 1.5 P ... ... method_not_allowed() options() Example views.py : from django.http import HttpResponse from django.views import View class MyView ( View ): def get ( self , request , * args , ** kwargs ): return HttpResponse ( "Hello, World!" ) Example urls.py : from ... django.urls import path from myapp.views import MyView urlpatterns = [ path ( "mine/" , MyView . as_view (), name = "my-view" ), ] 属性 http_method_names ¶ このビューが受け入れる ... classmethod as_view ( ** initkwargs ) ¶ リクエストを受け取ってレスポンスを返す、呼び出し可能なビューを返します: response = MyView . as_view ()( request ) 返されたビューは、 view_class と view_initkwargs 属性を持っています。 リクエスト/レスポンスサイクル ... ... method_not_allowed() options() Example views.py : from django.http import HttpResponse from django.views import View class MyView ( View ): def get ( self , request , * args , ** kwargs ): return HttpResponse ( "Hello, World!" ) Example urls.py : from ... django.urls import path from myapp.views import MyView urlpatterns = [ path ( "mine/" , MyView . as_view (), name = "my-view" ), ] 属性 http_method_names ¶ このビューが受け入れる ... classmethod as_view ( ** initkwargs ) ¶ リクエストを受け取ってレスポンスを返す、呼び出し可能なビューを返します: response = MyView . as_view ()( request ) 返されたビューは、 view_class と view_initkwargs 属性を持っています。 リクエスト/レスポンスサイクル ... ... ) クラスベースのビューでは以下のようになります。 from django.http import HttpResponse from django.views import View class MyView ( View ): def get ( self , request ): # <view logic> return HttpResponse ( "result" ) DjangoのURLリゾルバは、クラスではなく ... 定義されていない場合は HttpResponseNotAllowed を発生させます: # urls.py from django.urls import path from myapp.views import MyView urlpatterns = [ path ( "about/" , MyView . as_view ()), ] メソッドが関数ベースのビューが返すもの、つまり何らかの形の HttpR ... になります。 from django.http import HttpResponseRedirect from django.shortcuts import render from .forms import MyForm def myview ( request ): if request . method == "POST" : form = MyForm ( request . POST ) if form . is_valid (): # <process form clean ... ... ) クラスベースのビューでは以下のようになります。 from django.http import HttpResponse from django.views import View class MyView ( View ): def get ( self , request ): # <view logic> return HttpResponse ( "result" ) DjangoのURLリゾルバは、クラスではなく ... 定義されていない場合は HttpResponseNotAllowed を発生させます: # urls.py from django.urls import path from myapp.views import MyView urlpatterns = [ path ( "about/" , MyView . as_view ()), ] メソッドが関数ベースのビューが返すもの、つまり何らかの形の HttpR ... になります。 from django.http import HttpResponseRedirect from django.shortcuts import render from .forms import MyForm def myview ( request ): if request . method == "POST" : form = MyForm ( request . POST ) if form . is_valid (): # <process form clean ... ... です) 。 クラスベースビューは as_view() クラスメソッドを使って URL パターンに記述されます。 urlpatterns = [ path ( "view/" , MyView . as_view ( size = 42 )), ] ビューの引数によるスレッドの安全性 ビューから渡される引数は、ビューのすべてのインスタンスに共有 ... ます。 as_view() に渡された引数は、リクエストを処理するために使用されるインスタンスに割り当てられます。 前の例を使用すると、 MyView のすべてのリクエストが self.size を使用できることを意味します。 引数はクラスにすでに存在する属性に対応していなければなりま ... ... です) 。 クラスベースビューは as_view() クラスメソッドを使って URL パターンに記述されます。 urlpatterns = [ path ( "view/" , MyView . as_view ( size = 42 )), ] ビューの引数によるスレッドの安全性 ビューから渡される引数は、ビューのすべてのインスタンスに共有 ... ます。 as_view() に渡された引数は、リクエストを処理するために使用されるインスタンスに割り当てられます。 前の例を使用すると、 MyView のすべてのリクエストが self.size を使用できることを意味します。 引数はクラスにすでに存在する属性に対応していなければなりま ... 2026年10月08日