... 場合 ( middleware で設定されます) 、その値を ROOT_URLCONF の代わりに使います。 Django はその Python モジュールをロードして、 urlpatterns という名前の変数を探します。この変数の値は django.urls.path() または django.urls.re_path() インスタンスの sequence でなけれ ... Error handling を見てください。 カスタマイズ例 ¶ URLconf のサンプルです。 from django.urls import path from . import views urlpatterns = [ path ( "articles/2003/" , views . special_case_2003 ), path ( "articles/<int:year>/" , views . year_archive ), path ( ... , register_converter from . import converters , views register_converter ( converters . FourDigitYearConverter , "yyyy" ) urlpatterns = [ path ( "articles/2003/" , views . special_case_2003 ), path ( "articles/<yyyy:year>/" , views . year_archive ), ... , ... ... 場合 ( middleware で設定されます) 、その値を ROOT_URLCONF の代わりに使います。 Django はその Python モジュールをロードして、 urlpatterns という名前の変数を探します。この変数の値は django.urls.path() または django.urls.re_path() インスタンスの sequence でなけれ ... Error handling を見てください。 カスタマイズ例 ¶ URLconf のサンプルです。 from django.urls import path from . import views urlpatterns = [ path ( "articles/2003/" , views . special_case_2003 ), path ( "articles/<int:year>/" , views . year_archive ), path ( ... , register_converter from . import converters , views register_converter ( converters . FourDigitYearConverter , "yyyy" ) urlpatterns = [ path ( "articles/2003/" , views . special_case_2003 ), path ( "articles/<yyyy:year>/" , views . year_archive ), ... , ... ... : from django.urls import include , path urlpatterns = [ path ( "index/" , views . index , name = "main-view" ), path ( "bio/<username>/" , views . bio , name = "bio" ), path ... mple, <int:section> matches a string of decimal digits and converts the value to an int . リクエストを処理する際、Djangoは urlpatterns の最初のパターンから処理を開始し、リストを順番に進みながら、リクエストされたURLと各パターンを比較します。一致するパターンが ... 由については、 URL パターンの命名 を参照してください。 re_path() ¶ re_path ( route , view , kwargs = None , name = None ) ¶ urlpatterns に含める要素を返します。例えば: from django.urls import include , re_path urlpatterns = [ re_path ( r "^index/$" , views . ... ... : from django.urls import include , path urlpatterns = [ path ( "index/" , views . index , name = "main-view" ), path ( "bio/<username>/" , views . bio , name = "bio" ), path ... mple, <int:section> matches a string of decimal digits and converts the value to an int . リクエストを処理する際、Djangoは urlpatterns の最初のパターンから処理を開始し、リストを順番に進みながら、リクエストされたURLと各パターンを比較します。一致するパターンが ... 由については、 URL パターンの命名 を参照してください。 re_path() ¶ re_path ( route , view , kwargs = None , name = None ) ¶ urlpatterns に含める要素を返します。例えば: from django.urls import include , re_path urlpatterns = [ re_path ( r "^index/$" , views . ... ... py : from django.urls import path from django.views.generic.dates import ArchiveIndexView from myapp.models import Article urlpatterns = [ path ( "archive/" , ArchiveIndexView . as_view ( model = Article , date_field = "pub_date" ), name = "article_archive" ... = True allow_future = True 例 myapp/urls.py : from django.urls import path from myapp.views import ArticleYearArchiveView urlpatterns = [ path ( "<int:year>/" , ArticleYearArchiveView . as_view (), name = "article_year_archive" ), ] 例 myapp/article_archiv ... _date" allow_future = True 例 myapp/urls.py : from django.urls import path from myapp.views import ArticleMonthArchiveView urlpatterns = [ # Example: /2012/08/ path ( "<int:year>/<int:month>/" , ArticleMonthArchiveView . as_view ( month_format = "%m" ), nam ... ... py : from django.urls import path from django.views.generic.dates import ArchiveIndexView from myapp.models import Article urlpatterns = [ path ( "archive/" , ArchiveIndexView . as_view ( model = Article , date_field = "pub_date" ), name = "article_archive" ... = True allow_future = True 例 myapp/urls.py : from django.urls import path from myapp.views import ArticleYearArchiveView urlpatterns = [ path ( "<int:year>/" , ArticleYearArchiveView . as_view (), name = "article_year_archive" ), ] 例 myapp/article_archiv ... _date" allow_future = True 例 myapp/urls.py : from django.urls import path from myapp.views import ArticleMonthArchiveView urlpatterns = [ # Example: /2012/08/ path ( "<int:year>/<int:month>/" , ArticleMonthArchiveView . as_view ( month_format = "%m" ), nam ... ... latpages' を追加してください。 そして、下記のいずれかを行います: URLconf にエントリを追加します。例えば、次のようにします: urlpatterns = [ path ( "pages/" , include ( "django.contrib.flatpages.urls" )), ] または: django.contrib.flatpages.middleware.Flatpage ... フラットページをURLconfに含める方法はいくつかあります。以下のように、特定のパスをフラットページに割り当てることができます。 urlpatterns = [ path ( "pages/" , include ( "django.contrib.flatpages.urls" )), ] 「キャッチオール」パターンとして設定することもできま ... す。この場合、そのパターンを他の urlpatterns の最後に配置することが重要です。 from django.contrib.flatpages import views # Your other patterns here urlpatterns += [ re ... ... latpages' を追加してください。 そして、下記のいずれかを行います: URLconf にエントリを追加します。例えば、次のようにします: urlpatterns = [ path ( "pages/" , include ( "django.contrib.flatpages.urls" )), ] または: django.contrib.flatpages.middleware.Flatpage ... フラットページをURLconfに含める方法はいくつかあります。以下のように、特定のパスをフラットページに割り当てることができます。 urlpatterns = [ path ( "pages/" , include ( "django.contrib.flatpages.urls" )), ] 「キャッチオール」パターンとして設定することもできま ... す。この場合、そのパターンを他の urlpatterns の最後に配置することが重要です。 from django.contrib.flatpages import views # Your other patterns here urlpatterns += [ re ... ... port path from blog.models import Entry info_dict = { "queryset" : Entry . objects . all (), "date_field" : "pub_date" , } urlpatterns = [ # some generic view using info_dict # ... # the sitemap path ( "sitemap.xml" , sitemap , { "sitemaps" : { "blog" : Gen ... urls import path from .sitemaps import StaticViewSitemap from . import views sitemaps = { "static" : StaticViewSitemap , } urlpatterns = [ path ( "" , views . main , name = "main" ), path ( "about/" , views . about , name = "about" ), path ( "license/" , vi ... 数を受け取るべきです。 上記の例に対する関連するURLconfの行は、次のようになります: from django.contrib.sitemaps import views urlpatterns = [ path ( "sitemap.xml" , views . index , { "sitemaps" : sitemaps }, name = "django.contrib.sitemaps.views.index" , ), pa ... ... port path from blog.models import Entry info_dict = { "queryset" : Entry . objects . all (), "date_field" : "pub_date" , } urlpatterns = [ # some generic view using info_dict # ... # the sitemap path ( "sitemap.xml" , sitemap , { "sitemaps" : { "blog" : Gen ... urls import path from .sitemaps import StaticViewSitemap from . import views sitemaps = { "static" : StaticViewSitemap , } urlpatterns = [ path ( "" , views . main , name = "main" ), path ( "about/" , views . about , name = "about" ), path ( "license/" , vi ... 数を受け取るべきです。 上記の例に対する関連するURLconfの行は、次のようになります: from django.contrib.sitemaps import views urlpatterns = [ path ( "sitemap.xml" , views . index , { "sitemaps" : sitemaps }, name = "django.contrib.sitemaps.views.index" , ), pa ... 2026年10月08日