我有一个关于模板过滤器的问题。我使用了Django allauth来进行用户注册。我编辑了它的signup.html并使用循环来迭代字段以动态显示它们。我能够显示这些字段,但是无法定义类型字段。
我的做法是: account/signup.html
主应用程序(filters.py)中的模板过滤器
我正在使用Django allauth,我的模板过滤器代码应该放在哪里?扩展allauth表单以使用名字和姓氏的注册表单位于主应用程序中。
我的做法是: account/signup.html
{% load filters %}
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{% for field in forms.visible_fields %}
<input type="{{ field.field.widget|input_type}}" name="{{ field.name }}" id="{{ field.id_for_label}}" class="form-control">
{% endfor %}
</form>
主应用程序(filters.py)中的模板过滤器
from django import template
register = template.Library()
@register.filter('input_type')
def input_type(ob):
return ob.__class__.__name__
templates location
'DIRS': [os.path.join(BASE_DIR, 'templates')
我正在使用Django allauth,我的模板过滤器代码应该放在哪里?扩展allauth表单以使用名字和姓氏的注册表单位于主应用程序中。
main_app
是一个app吗?并且它是否被包含在INSTALLED_APPS
中? - Moses Koledoye