해결됨: django 템플릿에 예외 메시지가 제공되지 않음

주된 문제는 장고 템플릿에 제공된 예외 없음 메시지가 장고에만 국한되지 않는다는 것입니다. 모든 웹 개발 프레임워크와 함께 사용할 수 있습니다.

 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에서 드롭다운 목록을 어떻게 만듭니까? 예를 들어 "과일"이라는 데이터베이스 테이블에 다음 데이터가 저장되어 있다고 가정해 보겠습니다. 과일 ID 과일 이름 1 사과 2 바나나 3 오렌지 4 배 5 딸기 6 수박 7 파인애플 8 포도 9 키위 10 망고 11 파파야 12 복숭아 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에서 템플릿을 수정하는 몇 가지 방법이 있습니다. 가장 간단한 방법은 템플릿 태그를 사용하는 것입니다. 예를 들어 템플릿에 헤더를 추가하려면 다음을 수행합니다.

{% load header %} {% set header = "My Header" %} {% if not is_page %} {% set header = "My Header" %} {% endif %}

컨텍스트 프로세서를 사용하여 템플릿 변수의 컨텍스트를 변경할 수도 있습니다.

{% 로드 컨텍스트 %} {% 설정 컨텍스트 = "my_context" %} {% if not is_page %} {% 설정 컨텍스트 = "my_context" %} {% endif %}

관련 게시물:

코멘트 남김