Atrisināts: django veidne nav izņēmuma ziņojuma

Galvenā problēma ir tā, ka bez izņēmuma ziņojuma sniegtā django veidne nav specifiska Django. To var izmantot ar jebkuru tīmekļa izstrādes sistēmu.

 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 — kā izveidot Django nolaižamo sarakstu, izmantojot Python? django-templates Kā izveidot Django nolaižamo sarakstu, izmantojot Python? Piemēram, pieņemsim, ka jūsu datu bāzes tabulā ar nosaukumu “Augļi” ir saglabāti šādi dati: Augļa ID Augļa nosaukums 1 Ābols 2 Banāns 3 Apelsīns 4 Bumbieris 5 Zemenes 6 Arbūzs 7 Ananāsi 8 Vīnogas 9 Kivi 10 Mango 11 Papaija 12 Persiks 13 Ķirsis 14 Greipfrūts 15 Citrons 16 Laims 17 Kantalupa 18 Medusrasa 19 Akmens melone 20 Granātābols 21 Aprikoze 22 Avokado 23 Mellenes 24 Kazenes 25 Dzērvenes 26 Vīģes 27 Zirņi 28 Zirņi 29 Ērkšķogas 30 Zirņi 31 32 Ērkšķogas 33 Gvajava 34 Avenes 35 Zemenes 36 Tomāti 37 Ananāsi 38 Banāni 39 Mango 40 Apelsīns 41 Zemenes 42 Ķirsis 43 Ābols 44 Gvajava 45 Banāni 46 Mango 47 Apelsīns 48 Zemenes 49 Ķirši 50 Āboli 51 Gvajava 52 Āboli 53 Zemenes 54 Zemenes 55 Banāns 56 Mango 57 Apelsīns… Lasīt vairāk

Kā izmantot ārējo veidnes failu ar Django admin? django-templates Es mēģinu izmantot ārēju veidnes failu sava Django administratora lapai change_form.html. Dokumentācijā teikts: Lai ignorētu veidni change_form.html, vienkārši izveidojiet jaunu ar tādu pašu nosaukumu un ievietojiet to jebkurā no saviem TEMPLATE_DIRS direktorijiem. Bet es nezinu, kurā direktorijā to ievietot. Esmu mēģinājis to ievietot mapē /admin/change_form.html, /admin/change_form/, /admin/change/, /admin/chang/, /admi…Lasīt vairāk

Izņēmuma ziņojums

Ja Django notiek izņēmums, tas izdrukā ziņojumu konsolei. Šis ziņojums parasti satur informāciju par izņēmumu, piemēram, Python kodu, kas to izraisīja.

Modificēt veidnes

Ir daži veidi, kā Django modificēt veidnes. Vienkāršākais veids ir izmantot veidnes tagu. Piemēram, lai veidnei pievienotu galveni:

{% load header %} {% set header = "Mana galvene" %} {% if not is_page %} {% set header = "Mana galvene" %} {% endif %}

Varat arī izmantot konteksta procesoru, lai mainītu veidnes mainīgā kontekstu:

{% ielādēt kontekstu %} {% iestatīt kontekstu = "mans_konteksts" %} {% if not is_page %} {% set context = "my_context" %} {% endif %}

Related posts:

Leave a Comment