我已經嘗試以多種方式使用包含標記,例如分離 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/[email protected]_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 但我不知道如何使用它來呈現它。如果你知道,請描述我應該在哪里創建這個新文件來實現這個功能,我應該如何做。
添加回答
舉報
0/150
提交
取消