1

I want to show the Django choice field from Model on the HTML template like in the following picture. I can't see anything after doing this code.

models.py

class Author(models.Model):
    TITLE_CHOICES = [
        ('MR', 'Mr.'),
        ('MRS', 'Mrs.'),
        ('MS', 'Ms.'),
    ]
    
    title = models.CharField(max_length=3, choices=TITLE_CHOICES)
    

    

views.py

def AuthorView(request):
    form = Author(request.POST or None)
    title = Author.objects.all()

    context = {
        "form": form,
        "ttile": title,
    }
    if form.is_valid():
        form.save()

        return render(request, 'index.html')

    return render(request, 'index.html', context)

index.html

   <select name="confirm_type" id="confirm_type">
        {% for object in ttile %}

            <option value="by_email"> {{ object }} </option>
        {% endfor %}
   </select>

I want to show like this picture.

Prosenjit
  • 241
  • 5
  • 15

0 Answers0