💭

path("polls/", include("polls.urls")) の引数分析

に公開

メインのurls.pyに書かれているpath("polls/", include("polls.urls")) の引数は私は、最初引数の中身はルートとビューという理解でした。

引数の正体

path("polls/", include("polls.urls"))
     ↑        ↑
   第1引数   第2引数
  • 第1引数:"polls/" → URLパターン(ルート)
  • 第2引数:include("polls.urls") → 他のURLconfファイルの読み込んでいる。別のurls.pyファイルを読み込む関数

include()の仕組み

include("アプリ名.urls")

Discussion