为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用包含标签避免 RecursionError 将表单加载到 django 基本模板?

如何使用包含标签避免 RecursionError 将表单加载到 django 基本模板?

catspeake 2021-09-25 16:22:10
我已经尝试以多种方式使用包含标记,例如分离 html 文件并将其包含在基本模板(layout.html)中,甚至直接在基本模板(layout.html)上,我不断收到RecursionError at / maximum recursion depth exceeded在 app/forms.py 中class UserSettingsForm(forms.ModelForm):class Meta:    model = UserSettings    fields = ['theme_color','text_color']    widgets = {        'theme_color':forms.Select(attrs={'class':'form-control'}),        'text_color':forms.Select(attrs={'class':'form-control'})    }    error_messages = {        NON_FIELD_ERRORS : {            'unique_together': "%(model_name)s's %(field_labels)s are not unique.",        }    }在 app/templatetags/theme.py@register.inclusion_tag('layout.html')def settings_form():    set_form = UserSettingsForm()    return {'set_form':set_form}在 layout.html{% load theme %}...<form action="{% url 'set_settings' %}" method="post">   {% csrf_token %}}   {% settings_form %}   {{set_form}}</form>我希望表单显示在此 layout.html 扩展到的所有页面上,因此从视图发送它是不可能的。我一直听说 RequestContext 但我不知道如何使用它来呈现它。如果你知道,请描述我应该在哪里创建这个新文件来实现这个功能,我应该如何做。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 149 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信