Django form as GET

安稳与你 提交于 2020-01-03 02:28:05

问题


I want to have my site having form validation and xml generation by using GET. There will be no form rendering as HTML to fill, simply request will be a GET that parameters are generated automatically via a software.

Here is my form:

from django import forms
class xmlRetrievalForm(forms.Form):
    selected_date = forms.DateField(input_formats=['%d/%m/%Y',], error_messages={'required': 'selected_date is required (ie: 29/11/2011)', 'invalid': 'selected_date field is required (ie: 29/11/2011)'})
    start_time = forms.TimeField(error_messages={'required': 'start time is required (ie: 13:11)', 'invalid': 'start_time field is required (ie: 13:11)'})
    end_time = forms.TimeField(error_messages={'required': 'end time is required (ie: 13:11)', 'invalid': 'end_time field is required (ie: 13:11)'})
    channel_name = forms.CharField(max_length=30, error_messages={'required': 'channel_name 
field is required', 'invalid': 'enter a valid channel_name.'})

Now instead of POST, I need to receive form data as GET parameters,

How can I achieve this in the view ?

Regards


回答1:


I can't imagine where you are having trouble. Simply replace request.POST with request.GET when you instantiate the form.




回答2:


This ought to be what you're looking for: Using Django Forms For GET Urls.



来源:https://stackoverflow.com/questions/5430916/django-form-as-get

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!