我需要在网站的标题部分制作表单。此表单适用于我网站中的所有页面。例如,我在我的应用程序“帐户”中:
forms.py
class SignupForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)
class Meta:
model = User
fields = ('phone',)
views.py
def signup(request):
form = SignupForm(request.POST or None)
# CODE #
ctx = {
'form': form,
}
return render(request, 'accounts/signup.html', ctx)
urls.py
from django.urls import path
from . import views
app_name = 'accounts'
urlpatterns = [
path('signup/', views.signup, name='signup'),
]
帐户/ signup.html
{% block signup %}
{{ form }}
{% endblock %}
如果我将{% include 'accounts/signup.html' %}
添加到我的_base.html,我不会,请填写表单 - {{form}},但会包含所有其他内容。
你能告诉我如何获得网站中所有页面的表格吗?这是正确的做法吗?