# models.py
class Test(models.Model):
username = models.CharField(max_length=100)
email = models.EmailField()
# forms.py
class TestForm(forms.ModelForm):
username = forms.CharField()
email = forms.EmailField()
class Meta:
model = Test
fields = ('username', 'email')
# views.py
def test(request):
email = "example@example.com"
"""
How to pass and show the 'email' in django form/template?
"""
if request.method == 'POST':
form = TestForm(request.POST)
if form.is_valid():
form.save()
return redirect('home')
else:
form = TestForm()
return render(request, 'test.html', {"form": form})
我怎么能
价值
email
变量(即,
example@example.com
)以Django格式/模板作为
read-only field
?