I have following snippets,
# 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})
How can I show and re-use the value of email
variable (ie,example@example.com
) in Django form/template as a read-only field
?