Exemple de comment avoir un champ caché dans un formulaire avec Django:
models.py
from django.db import models
from django import forms
class MyForm(forms.Form):
MyHiddenParameter = forms.CharField(widget=forms.HiddenInput())
urls.py
url(r'^test/$', 'MyApp.views.MyView')
views.py
from MyApp.models import MyForm
def MyView(request,path):
if request.method == 'POST':
form = MyForm(request.POST)
if form.is_valid():
print form.cleaned_data[ 'MyHiddenParameter' ]
return render_to_response("MyApp/MyTemplate.html",
context_instance=RequestContext(request))
MyTemplate.html
<form action="http://127.0.0.1:8000/test/" method="post">
{% csrf_token %}
<input type='hidden' name="MyHiddenParameter" value="4" />
<input type="submit" value="Correction" />
</form>
Recherches associées
Liens | Site |
---|---|
Widgets | Django Doc |
html - hidden field | tizag |
Forms | html.com |
HIDDEN FIELD | echoecho |
Change a django form field to a hidden field | stackoverflow |
Django ModelForm to have a hidden input | stackoverflow |
Django ModelForm to have a hidden input | stackoverflow |