How can I say if field is not "album_logo" then do this else do that?
I have this code in my django form where I want to set the input for the field "album_logo" to be file and not text and to achieve this, I had to use the forloop.last since this field "album_logo" is the last field. But let's say it wasn't the last field then is there a better way to do this?
I have this code in my django form where I want to set the input for the field "album_logo" to be file and not text and to achieve this, I had to use the forloop.last since this field "album_logo" is the last field. But let's say it wasn't the last field then is there a better way to do this?
{% extends 'music/base.html' %} {% block title %}Add a New Album{% endblock %} {% block body %} <form method="post" enctype="multipart/form-data"> {% csrf_token %} {% for field in form %} {% if not forloop.last %} <label for="{{ field.id_for_label }}">{{ field.label }}</label> <input type="text" id="{{ field.id_for_label }}" name="" value=""> {% else %} <label for="{{ field.id_for_label }}">{{ field.label }}</label> <input type="file" id="{{ field.id_for_label }}" aceept="image/*" name="" value=""> {% endif %} {% endfor %} <input type="submit" value="Add"> </form> {% endblock %}