Created
November 30, 2013 02:57
-
-
Save xpander54/7714837 to your computer and use it in GitHub Desktop.
django forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://docs.djangoproject.com/en/dev/ref/forms/fields/ | |
https://docs.djangoproject.com/en/dev/topics/forms/ | |
crear forms.py en la carpeta junto a urls.py y settings.py | |
<strong>en forms.py</strong> | |
from django import forms | |
class ContactForm(forms.Form): | |
class ContactForm(forms.Form): | |
subject = forms.CharField(max_length=100) | |
message = forms.CharField() | |
email = forms.EmailField() | |
nombre = forms.CharField() | |
en views.py | |
from cgv.forms import ContactForm | |
from django.http import HttpResponseRedirect | |
def contacto(request): | |
forma_contacto = ContactForm() | |
context={ | |
'forma_contacto' : forma_contacto, | |
} | |
return render(request, 'contacto.html', context) | |
en html | |
<form action="/Contacto/" method="post"> | |
{% csrf_token %} | |
{{ forma_contacto.non_field_errors }} | |
<div class="fieldWrapper"> | |
{{ forma_contacto.nombre.errors }} | |
<label for="id_cc_myself">Nombre</label> | |
{{ forma_contacto.nombre }} | |
</div> | |
<div class="fieldWrapper"> | |
{{ forma_contacto.subject.errors }} | |
<label for="id_subject">Asunto:</label> | |
{{ forma_contacto.subject }} | |
</div> | |
<div class="fieldWrapper"> | |
{{ forma_contacto.email.errors }} | |
<label for="id_sender">e-mail:</label> | |
{{ forma_contacto.email }} | |
</div> | |
<div class="fieldWrapper"> | |
{{ forma_contacto.message.errors }} | |
<label for="id_message">Mensaje:</label> | |
{{ forma_contacto.message }} | |
</div> | |
<p><input type="submit" value="Enviar" /></p> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment