... したい場合は 、 sign_object() と unsign_object() メソッドを使います。 >>> signed_obj = signer . sign_object ({ "message" : "Hello!" }) >>> signed_obj 'eyJtZXNzYWdlIjoiSGVsbG8hIn0:bzb48DBkB-bwLaCnUVB75r5VAPUEpzWJPrTb80JMIXM' >>> obj = signer . unsign_ob ... ject ( signed_obj ) >>> obj {'message': 'Hello!'} 詳細は 複雑なデータ構造の保護 を参照してください。 何らかの理由により署名の値が書き換わってしまった場合、 django.core.s ... er . sign ( "My string" ) 'My string:v9G-nxfz3iQGTXrePqYPlGvH79WTcIgj1QIQSUODTW0' >>> signer . sign_object ({ "message" : "Hello!" }) 'eyJtZXNzYWdlIjoiSGVsbG8hIn0:bzb48DBkB-bwLaCnUVB75r5VAPUEpzWJPrTb80JMIXM' >>> signer = Signer ( salt = "extra" ) >>> ... ... い。 コメント テンプレートの行の一部をコメントアウトするには、コメント構文 {# #} を使います。 たとえば、このテンプレートは 'hello' としてレンダリングされます: {# greeting #} hello コメントには、たとえ無効でも、どんなテンプレート・コードも含めることがで ... 上書きされます。たとえば、このテンプレートは title ブロックの内容を常に上書きします: {% if change_title %} {% block title %} Hello! {% endblock title %} {% endif %} 最後に、同じテンプレート内で同じ名前の block タグを複数定義することはできないことに留意し ... 結果に悪影響を与えるというリスクが常に付きまといます。たとえば、テンプレートに以下のような部分がある場合を考えてみましょう: Hello, {{ name }} 一見、このコードはユーザの名前を表示するだけの無害なものに見えます。しかし次のような値が名前として入力されてい ... ... uld use only plain variable and property access, with prior local variable assignment for more complex cases: # Allowed f "hello { user } " f "hello { user . name } " f "hello { self . user . name } " # Disallowed f "hello { get_user () } " f "you are ... { user . age * 365.25 } days old" # Allowed with local variable assignment user = get_user () f "hello { user } " user_days_old = user . age * 365.25 f "you are { user_days_old } days old" f-strings should not be used for any ... ... るかの例をいくつか示します: {% if "bc" in "abcdef" %} This appears since "bc" is a substring of "abcdef" {% endif %} {% if "hello" in greetings %} If greetings is a list or set, one element of which is the string "hello", this will appear. {% endif %} ... できる最初のものが使用されます。 include されたテンプレートは、include した側のコンテキストにおいて解釈されます。以下の例は "Hello, John!" を出力します: コンテキスト: 変数 person に "John" を、変数 greeting に "Hello" をセット。 テンプレート: {% include ... って、テンプレートに追加のコンテキストを渡すことができます: {% include "name_snippet.html" with person = "Jane" greeting = "Hello" %} あらかじめ準備された変数だけを使って (あるいは変数をまったく使わずに) 出力させたい場合は only オプションを使います。テ ... ... ジェクトとして振る舞い、Django の FileResponse オブジェクトがファイルライクなオブジェクトを受け取るということです。 ここに、"Hello World"の例を示します: import io from django.http import FileResponse from reportlab.pdfgen import canvas def some_view ( r ... DF generation happens. # See the ReportLab documentation for the full list of functionality. p . drawString ( 100 , 100 , "Hello world." ) # Close the PDF object cleanly, and we're done. p . showPage () p . save () # FileResponse sets the Content-Disp ... present the option to save the file. buffer . seek ( 0 ) return FileResponse ( buffer , as_attachment = True , filename = "hello.pdf" ) コードとコメントが自分自身の意味を説明しているはずですが、いくつかの点には言及しておくべきでしょう。 レスポンスはフ ... ... インドするには、辞書型のデータを Form クラスのコンストラクタの最初のパラメータとして渡します。 >>> data = { ... "subject" : "hello" , ... "message" : "Hi there" , ... "contact_email" : "foo@example.com" , ... "urgent" : True , ... } >>> f = ContactForm ... ムの is_bound 属性の値を確認してください。 >>> f = ContactForm () >>> f . is_bound False >>> f = ContactForm ({ "subject" : "hello" }) >>> f . is_bound True 空の辞書を渡すと、データが空の バインドされた フォームが作成されることに注意してください。 >>> f ... lid() メソッドを呼び出して検証を実行し、データが有効であるかどうかを示すブール値を返します。 >>> data = { ... "subject" : "hello" , ... "message" : "Hi there" , ... "contact_email" : "foo@example.com" , ... "urgent" : True , ... } >>> f = ContactForm ... ... he 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" ) a ... ップします。 element_id パラメータが None でない場合、 <script> タグに渡されたidが与えられます。例えば: >>> json_script ({ "hello" : "world" }, element_id = "hello-data" ) '<script id="hello-data" type="application/json">{"hello": "world"}</script>' en ... _html() を使用するべきです。 マークされた文字列を安全としても、変更されると再び安全でなくなります。例えば: >>> mystr = "<b>Hello World</b> " >>> mystr = mark_safe ( mystr ) >>> type ( mystr ) <class 'django.utils.safestring.SafeString'> >>> mystr = my ... ... 作成することです: >>> from django.core.files import File # Create a Python file object using open() >>> f = open ( "/path/to/hello.world" , "w" ) >>> myfile = File ( f ) これで、 File クラスのドキュメント化された属性とメソッドのすべてを使えるようになりま ... django.core.files import File # Create a Python file object using open() and the with statement >>> with open ( "/path/to/hello.world" , "w" ) as f : ... myfile = File ( f ) ... myfile . write ( "Hello World" ) ... >>> myfile . closed True >>> f . cl ... ... : "Invalid block tag: 'syntax'" , "source_lines" : [ ( 1 , "some \n " ), ( 2 , "lines \n " ), ( 3 , "before \n " ), ( 4 , "Hello { % s yntax error %} {{ world }} \n " ), ( 5 , "some \n " ), ( 6 , "lines \n " ), ( 7 , "after \n " ), ( 8 , "" ), ], "lin ... e" : 4 , "before" : "Hello " , "during" : "{ % s yntax error %}" , "after" : " {{ world }} \n " , "total" : 9 , "bottom" : 9 , "top" : 1 , } Origin A ... ... く作成されたオブジェクトを返します: >>> b = Blog . objects . get ( id = 1 ) >>> e = b . entry_set . create ( ... headline = "Hello" , body_text = "Hi" , pub_date = datetime . date ( 2005 , 1 , 1 ) ... ) # No need to call e.save() at this point -- it's a ... コードと等価です(しかし、よりシンプルです): >>> b = Blog . objects . get ( id = 1 ) >>> e = Entry ( blog = b , headline = "Hello" , body_text = "Hi" , pub_date = datetime . date ( 2005 , 1 , 1 )) >>> e . save ( force_insert = True ) リレーションシップ ... 2026年10月08日