Friday, 23 August 2013

differentiating between different post requests on the same page in Django views.py

differentiating between different post requests on the same page in Django
views.py

I have a web page that I am looking to be able to modify dynamically with
multiple post requests. basically there are two methods that the user can
submit text to be uploaded into models; one is through a text input field
and the other is through a file upload field. How do I set up my python
conditionals to do this? I want to be able to differentiate between the
two post request with if and statements. What is the differentiating
variable that I should use to tell these two apart. My views.py so far has
the text input working.
def homesite(request):
corpusitems = CorpusItem.objects.order_by('name')
if (request.method == 'POST'):
f = CorpusItemForm(request.POST)
if f.is_valid():
new_corpusitem = f.save()
return render(request, 'content.html', {'corpusitems': corpusitems})

No comments:

Post a Comment