... 使います。 Django はその Python モジュールをロードして、 urlpatterns という名前の変数を探します。この変数の値は django.urls.path() または django.urls.re_path() インスタンスの sequence でなければなりません。 Django は URL パターンを順に調べて、 path_in ... 数として提供されます。 指定された URL パス表現でマッチした名前付き部分からはキーワード引数が作られます。ただし、 django.urls.path() や django.urls.re_path() に kwargs オプション引数が指定されていた場合は、その中の引数で上書きされます。 もし、 URL 正規表 ... グビューを呼び出します。下の Error handling を見てください。 カスタマイズ例 URLconf のサンプルです。 from django.urls import path from . import views urlpatterns = [ path ( "articles/2003/" , views . special_case_2003 ), path ( "articles/<int:year>/" , ... ... = "57 Chevy" ) >>> car . photo <ImageFieldFile: cars/chevy.jpg> >>> car . photo . name 'cars/chevy.jpg' >>> car . photo . path '/media/cars/chevy.jpg' >>> car . photo . url 'https://media.example.com/cars/chevy.jpg' このオブジェクト(例では car.phot ... )からの相対パスを指定することで、ファイル名を変更できます: >>> import os >>> from django.conf import settings >>> initial_path = car . photo . path >>> car . photo . name = "cars/chevy_ii.jpg" >>> new_path = os . path . join ( settings . MEDIA_ROOT ... , car . photo . name ) >>> # Move the file on the filesystem >>> os . rename ( initial_path , new_path ) >>> car . save () >>> car . photo . path '/media/cars/chevy_ii.jpg' >>> car . photo . path == new_path True デ ... ... "main-view" ), path ( "bio/<username>/" , views . bio , name = "bio" ), path ( "articles/<slug:title>/" , views . article , name = "article-de ... tail" ), path ( "articles/<slug:title>/<int:section>/" , views . section , name = "article-section" ), path ( "blog/" , include ( "blog. ... のファイルを変更するだけで済むようになります。 name 引数が有用な理由については、 URL パターンの命名 を参照してください。 re_path() re_path ( route , view , kwargs = None , name = None ) urlpatterns に含める要素を返します。例えば: from django.urls impo ... ... リのパスは、個々のユーザーごとに環境変数を設定するか、システム全体のライブラリ パスを構成することで設定できます。 LD_LIBRARY_PATH 環境変数 A user may set this environment variable to customize the library paths they want to use. The typical library dir ... ectory for software built from source is /usr/local/lib . Thus, /usr/local/lib needs to be included in the LD_LIBRARY_PATH variable. For example, the user could place the following in their bash profile: export LD_LIBRARY_PATH = /usr/local/lib シ ... ライブラリのパスを設定する On GNU/Linux systems, there is typically a file in /etc/ld.so.conf , which may include additional paths from files in another directory, such as /etc/ld.so.conf.d . As the root user, add the custom library path (like /usr/loc ... ... _wsgiをインストールして有効にしたら、Apacheサーバーの httpd.conf ファイルを編集して、以下を追加します。 WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py WSGIPythonHome /path/to/venv WSGIPythonPath /path/to/mysite.com <Directory /path/to/mysite.co ... 場合は、 WSGIPythonHome を使ってパスを追加します。詳しくは mod_wsgi virtual environment guide を参照してください。 WSGIPythonPath の行は、プロジェクトのパッケージは Python のパス上でインポートすることが可能であることを保証します。言い換えると、 import ... な WSGIDaemonProcess と WSGIProcessGroup ディレクティブを追加する必要があります。デーモンモードを使用する場合には WSGIPythonPath を使用できないため、上記設定にさらなる変更が求められます。代わりに WSGIDaemonProcess に python-path オプションを使用する必 ... ... ate を実行します。 しくみ manage.py migrate はデータベースに django_redirect テーブルを作成します。これは、 site_id 、 old_path 、および new_path フィールドを持つルックアップテーブルです。 RedirectFallbackMiddleware が全ての作業を担当しています。Djan ... たびに、このミドルウェアは要求されたURLが最終手段としてリダイレクトデータベースをチェックします。具体的には、与えられた old_path とサイトIDが SITE_ID 設定に対応するリダイレクトを確認します。 一致するものが見つかり、かつ new_path が空でない場合、 ... 301 ("Moved Permanently") リダイレクトで new_path にリダイレクトします。 RedirectFallbackMiddleware をサブクラス化し、 response_redirect_class を django.http.HttpRespon ... ... れない場合、次のエラーが発生します: ImportError: Could not find the GEOS library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your settings. 最も一般的な解決策は、 ライブラリの環境設定 を適切に設定するか、 または 設定で GEOS_LIBRARY_PATH を設定す ... ナリパッケージを使用する場合 (たとえばUbuntu上で) 、 binutils をインストールする が必要になる可能性があります。 GEOS_LIBRARY_PATH If your GEOS library is in a non-standard location, or you don't want to modify the system's library path then the GEOS_LI ... BRARY_PATH setting may be added to your Django settings file with the full path to the GEOS C library. For example: GEOS_LIBRARY_PATH ... ... を用いた月や日に変更できます。これは、すべてのサブクラスのビューに適用されます。 例 myapp/urls.py : from django.urls import path from django.views.generic.dates import ArchiveIndexView from myapp.models import Article urlpatterns = [ path ( "archive/" ... ts . all () date_field = "pub_date" make_object_list = True allow_future = True 例 myapp/urls.py : from django.urls import path from myapp.views import ArticleYearArchiveView urlpatterns = [ path ( "<int:year>/" , ArticleYearArchiveView . as_view (), ... eryset = Article . objects . all () date_field = "pub_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>/" , Ar ... ... イトでサイトマップの生成を有効にするには、 URLconf に以下の行を追加します: from django.contrib.sitemaps.views import sitemap path ( "sitemap.xml" , sitemap , { "sitemaps" : sitemaps }, name = "django.contrib.sitemaps.views.sitemap" , ) これは Django に ... ity methods. location [ソース] オプション。 メソッドまたは属性のいずれか。 If it's a method, it should return the absolute path for a given object as returned by items() . If it's an attribute, its value should be a string representing an absolute pa ... om django.contrib.sitemaps import GenericSitemap from django.contrib.sitemaps.views import sitemap from django.urls import path from blog.models import Entry info_dict = { "queryset" : Entry . objects . all (), "date_field" : "pub_date" , } urlpatter ... ... ar on the default page generated by the django.views.defaults.page_not_found() view. The URL path is no longer displayed in the default 404 template and the request_path context variable is now quoted to fix the issue fo ... r custom templates that use the path. ... 2026年10月08日