... な CSS と JavaScript の組み合わせは、そのページに使用されるウィジェットによって異なります。 ここでアセット定義の出番です。Django では異なるファ ... teFields を描画するのにカレンダーを使いたい場合、独自の Calendar ウィジェットを定義したとき、このウィジェットは CSS や JavaScript と紐付けることができます。フォーム上でこの Calendar ウィジェットを使用するとき、Django は必要な CSS および JavaScript のフ ... ら、ご自分の アプリケーションで自由に使ってください!これらは全て django.contrib.admin.widgets に格納されています。 どの JavaScript ツールキットを使えばいいの? 多くの JavaScript ツールキットが存在し、その多くにはウィジェット (カレンダ ーウィジェットなど) ... ... olicy, beside the basic config, you need to: Include the NONCE placeholder value in the CSP settings. This only applies to script-src or style-src directives: from django.utils.csp import CSP SECURE_CSP = { "default-src" : [ CSP . SELF ], # Allow self- ... hosted scripts and script tags with matching `nonce` attr. "script-src" : [ CSP . SELF , CSP . NONCE ], # Example of the less secure 'un ... .context_processors.csp" , ], }, }, ] In your templates, add the nonce to elements that require it: For inline <style> or <script> tags, use the csp_nonce context variable directly: < style nonce = " {{ csp_nonce }} " > /* These inline styles will be a ... ... urces from the same origin (same scheme, host, and port). STRICT_DYNAMIC Represents 'strict-dynamic' . Allows execution of scripts loaded by a trusted script (e.g., one with a valid nonce or hash), without needing 'unsafe-inline' . UNSAFE_EVAL Represen ... ts 'unsafe-eval' . Allows use of eval() and similar JavaScript functions. Strongly discouraged. UNSAFE_HASHES Represents 'unsafe-hashes' . Allows inline event handlers and some javascri ... t hashes match a policy rule. Requires CSP Level 3+. UNSAFE_INLINE Represents 'unsafe-inline' . Allows execution of inline scripts, styles, and javascript: URLs. Generally discouraged, especially for scripts. WASM_UNSAFE_EVAL Represents 'wasm-unsafe-ev ... ... a nonce="<value>" HTML attribute when the csp() context processor is configured, and an empty string otherwise. Use it in <script> or <link> elements to allow them under a nonce-based Content Security Policy: < script src = "/path/to/script.js" {% csp_ ... nonce_attr %} ></ script > < link rel = "stylesheet" href = "/path/to/style.css" {% csp_nonce_attr %} > When called with a Media object as the argu ... ment, renders its assets with the CSP nonce applied to each <script> and <link> element: {% csp_nonce_attr form.media %} In both forms, if the context processor is not configured, assets are ... ... or these redirects (namely django.utils.http.is_safe_url() ) didn't check if the scheme is http(s) and as such allowed javascript:... URLs to be entered. If a developer relied on is_safe_url() to provide safe redirect targets and put such a URL into a ... sn't affect Django currently, since we only put this URL into the Location response header and browsers seem to ignore JavaScript there. XSS vulnerability in django.contrib.admin If a URLField is used in Django 1.5, it displays the current value of the ... anyToManyField if it has a Unicode name parameter (#20207). Ensured that the WSGI request's path is correctly based on the SCRIPT_NAME environment variable or the FORCE_SCRIPT_NAME setting, regardless of whether or not either has a trailing slash (#201 ... ... {% extends 'admin/change_form.html' %} {% load static %} {% block admin_change_form_document_ready %} {{ block .super }} < script src = " {% static 'app/formset_handlers.js' %} " ></ script > {% endblock %} app/static/app/formset_handlers.js document . ... mset:removed' , ( event ) => { // Row removed }); 注意点が2つあります: もし admin/change_form.html を継承しているなら、JavaScript コードはテンプレートブロック内に配置する必要があります。そうしないと、最終的な HTML にレンダリングされません。 Django の a ... dmin_change_form_document_ready ブロックには、変更フォーム内でのさまざまな操作を処理するための JavaScript コードが含まれており、 {{ block.super }} は、それらもレンダリングする必要があるために追加されています。 バージョン4.1より前 ... ... on in Django 3.1 that caused the incorrect prefixing of STATIC_URL and MEDIA_URL settings, by the server-provided value of SCRIPT_NAME (or / if not set), when set to a URL specifying the protocol but without a top-level domain, e.g. http://myhost/ ( #3 ... ... st" ] = request try : view ( * args , ** kwargs ) except Http404 : return HttpResponseRedirect ( "/" ) return response get_script_prefix() get_script_prefix () [ソース] 通常、アプリケーション内でURLを定義する際には、常に reverse() を使用すべきです。しか ... ジェクトのベースURLをそのWebサーバー内で見つける必要があります(通常、 reverse() がこれを処理します)。そのような場合、 get_script_prefix() を呼び出すことができます。これは、DjangoプロジェクトのURLのスクリプトプレフィックス部分を返します。あなたのDjango ... ... ote that this method does not encode the ' character, as it is a valid character within URIs. See encodeURIComponent() JavaScript function for more details. エンコードされた結果を含む ASCII 文字列を返します。 escape_uri_path ( path ) [ソース] URI (Unif ... Rss201rev2Feed ( ... title = "Poynter E-Media Tidbits" , ... link = "https://www.poynter.org/tag/e-media-tidbits/" , ... description = "A group blog by the sharpest minds in online media/journalism/publishing." , ... language = "en" , ... ) >>> feed . ... add_item ( ... title = "Hello" , ... link = "https://www.holovaty.com/test/" , ... description = "Testing." , ... ) >>> with open ( "test.rss" , "w" ) as fp : ... feed . write ( fp , "utf-8" ) ... ジェネレータの選択 ... ... る必要があります。Django におけるユーザー入力の検証については、 フォームに関するドキュメント を参照してください。 Cross-site scripting (XSS) protection In a cross-site scripting attack, malicious code in the form of a client-side script is injected into ... another user's web browser, where it will be executed. This is typically done by: storing the malicious script in the database where it will be retrieved and presented to other users in their browsers, or getting users to click a lin ... k which will cause the attacker's JavaScript to be executed by the user's browser. Cross-site scripting attacks can originate from any untrusted source of data, includ ... 2026年10月08日