A
A
AlexNest2021-01-08 11:38:19
Django
AlexNest, 2021-01-08 11:38:19

How to organize dynamic display of data from the database in django?

There is a task - to dynamically display data from the help base of the drop-down list.
(In the case of php, this is pretty easy to do with an ajax request.)
Is there a basic way in django to solve this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2021-01-08
@AlexNest

JsonResponse
Also useful: csrf ajax

(In the case of php, this is fairly easy to do with an ajax request.)

It's easy to do this in django too.

S
Sergey, 2021-01-09
@SergeiKl

You can do this:

<p><select name="pr" required id="prepod">
      <option selected  value="0">Выбрать</option>
      {% for prepod in prepods %}
        <option value="{{ prepod.pk }}">{{ prepod.name }}</option>
      {% endfor %}
      </select>
      <input type="submit" value="Отправить"></p>

Or in forms.py you create:
class PrepodForms(forms.ModelForm):
    prepodname = forms.ModelChoiceField(queryset = Prepod.objects.all(),
                empty_label="Выберите преподавателя",
                widget=forms.widgets.Select(attrs={'class':'dropdown'}),label="Преподаватель")

    class Meta:
        model = Prepod
        fields = ()

and paste in html:
{{ grform.gruppname }}
    <input type="submit" value="Показать расписание">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question