已解決:沒有提供異常消息的 django 模板

主要問題是提供的 django 模板無異常消息不是特定於 Django 的。 它可以與任何 Web 開發框架一起使用。

 I have a form with a field that is required. If the user submits the form without filling in the required field, I want to display an error message. This is my view: def add_item(request): if request.method == 'POST': form = ItemForm(request.POST) if form.is_valid(): item = Item() item.name = request.POST['name'] item.save() return HttpResponseRedirect('/items/') else: return render_to_response('items/add_item... Read More

Django - How to use a custom decorator with class based views? django-templates I have been trying to use a custom decorator with Django's class based views but it doesn't seem to work as expected and I can't figure out why? Here's what I'm doing: from django import template from django... Read More

How do you create a dropdown list in Django using Python? django-templates How do you create a dropdown list in Django using Python? For example, let's say that you have the following data stored in your database table called "Fruit": Fruit ID Fruit Name 1 Apple 2 Banana 3 Orange 4 Pear 5 Strawberry 6 Watermelon 7 Pineapple 8 Grapes 9 Kiwi 10 Mango 11 Papaya 12 Peach 13 Cherry 14 Grapefruit 15 Lemon 16 Lime 17 Cantaloupe 18 Honeydew 19 Rockmelon 20 Pomegranate 21 Apricot 22 Avocado 23 Blueberry 24 Blackberry 25 Cranberry 26 Fig 27 Gooseberry 28 Guava 29 Jackfruit 30 Lychee 31 Mulberry 32 Nectarine 33 Orange 34 Peach 35 Pear 36 Plum 37 Prune 38 Raspberry 39 Strawberry 40 Tomato 41 Pineapple 42 Banana 43 Mango 44 Orange 45 Strawberry 46 Cherry 47 Apple 48 Guava 49 Banana 50 Mango 51 Orange 52 Strawberry 53 Cherry 54 Apple 55 Guava 56 Banana 57 Mango 58 Orange 59 Strawberry 60 Cherry 61 Apple 62 Guava 63 Banana 64 Mango 65 Orang...Read More

Django – 如何使用 Python 在 Django 中創建下拉列表? django-templates 如何使用 Python 在 Django 中創建下拉列表? 例如,假設您在名為“Fruit”的數據庫表中存儲了以下數據: Fruit ID Fruit Name 1 Apple 2 Banana 3 Orange 4 Pear 5 Strawberry 6 Watermelon 7 Pineapple 8 Grapes 9 Kiwi 10 Mango 11 Papaya 12 Peach 13櫻桃 14 葡萄柚 15 檸檬 16 酸橙 17 哈密瓜 18 蜜瓜 19 哈密瓜 20 石榴 21 杏 22 鱷梨 23 藍莓 24 黑莓 25 蔓越莓 26 無花果 27 醋栗 28 番石榴 29 菠蘿蜜 30 荔枝 31 桑葚 32 油桃 33 橙子 34 桃子 35 洋李子 36 37 梨子 38覆盆子39草莓40番茄41菠蘿42香蕉43芒果44橙子45草莓46櫻桃47蘋果48番石榴49香蕉50芒果51橙子52草莓53櫻桃54蘋果55番石榴56香蕉57芒果58橙子59草莓60櫻桃61蘋果62番石榴63香蕉 64 芒果 65 紅毛猩猩……閱讀更多

如何在 Django admin 中使用外部模板文件? django-templates 我正在嘗試為我的 Django 管理員的 change_form.html 頁面使用外部模板文件。 文檔說:要覆蓋 change_form.html 模板,只需創建一個具有相同名稱的新模板並將其放在任何一個 TEMPLATE_DIRS 目錄中。 但我不確定將它放在哪個目錄中。我試過將它放在 /admin/change_form.html、/admin/change_form/、/admin/change/、/admin/chang/、/admi 下……閱讀更多

異常信息

當 Django 中發生異常時,它會向控制台打印一條消息。 此消息通常包含有關異常的信息,例如導致異常的 Python 代碼。

修改模板

有幾種方法可以在 Django 中修改模板。 最簡單的方法是使用模板標籤。 例如,要將標題添加到模板:

{% 加載標頭 %} {% set header = “我的標頭” %} {% if not is_page %} {% set header = “我的標頭” %} {% endif %}

您還可以使用上下文處理器來更改模板變量的上下文:

{% 加載上下文 %} {% 設置上下文 = “my_context” %} {% 如果不是 is_page %} {% 設置上下文 = “my_context” %} {% endif %}

相關文章:

發表評論