Фильтровать шаблоны по ChoiceField - Django

Возвращает первую длинную общую подстроку:

def compareTwoStrings(string1, string2):
    list1 = list(string1)
    list2 = list(string2)

    match = []
    output = ""
    length = 0

    for i in range(0, len(list1)):

        if list1[i] in list2:
            match.append(list1[i])

            for j in range(i + 1, len(list1)):

                if ''.join(list1[i:j]) in string2:
                    match.append(''.join(list1[i:j]))

                else:
                    continue
        else:
            continue

    for string in match:

        if length < len(list(string)):
            length = len(list(string))
            output = string

        else:
            continue

    return output
0
задан NeoVe 2 March 2019 в 21:33
поделиться

1 ответ

Можно использовать {% include %} с переменной.

def some_view_after_post(request):
    # ... lookup value of myfield2 ...
    return render(request, "path/to/after_post.html", {'myfield2: myfield2})

В шаблоне after_post.html:

<!-- include a template based on user's choice -->
<div class="user-choice">
{% include myfield2 %}
</div>

Вы должны убедиться, что нет никакого способа, которым пользователь может ввести ошибочный выбор. Например, убедитесь, что значение myfield2 selection допустимо, прежде чем добавлять его в контекст.

0
ответ дан bogeymin 2 March 2019 в 21:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: