def form_valid(self, form): proxy = Proxy(self.request.user) try: upload = self.request.FILES['file'] proxy.upload(upload) except KeyError: try: if self.request.POST['url']: proxy.resolve(self.request.POST['url']) else: raise Exception('Please upload file or enter URL') except Exception, e: messages.add_message(self.request, messages.ERROR, e.message) return self.get(self.request)