Ответ 1
Да. Это очень возможно. Вы можете читать объекты формы. Это было бы так же, как вы относились бы к ModelForm
, за исключением того, что вы не связаны моделью, и вам нужно явно объявить все атрибуты формы.
def form_handle(request):
form = MyForm()
if request.method=='POST':
form = MyForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
#now in the object cd, you have the form as a dictionary.
a = cd.get('a')
#blah blah encode parameters for a url blah blah
#and make another post request
#edit : added ": " after if request.method=='POST'
и
class MyForm(forms.Form): #Note that it is not inheriting from forms.ModelForm
a = forms.CharField(max_length=20)
#All my attributes here
В шаблоне:
<form action="{% url form_handle %}" method="POST">{% csrf_token %}
{{form.as_p}}
<button type="submit">Submit</button>
</form>