Skip to content Skip to sidebar Skip to footer

Django : Error With Form_valid And Get_full_path()

I am trying to acquire the current tenant's domain name through a form. I am trouble with writing the view that would achieve that. here is my form.py: class ETL(forms.Form):

Solution 1:

form_valid has no request as first parameter. The parameters are self and form. You can access the request object with self.request:

classGetfilesView(LoginRequiredMixin, FormView):
    template_name = 'upload.html'
    form_class = ETL
    success_url = 'Home'defform_valid(self, form):
        url = self.request.get_full_path()
        form.process_data()

        returnsuper().form_valid(form)

Note that your form has no request either. You can pass data, for example through the method parameters:

classGetfilesView(LoginRequiredMixin, FormView):
    template_name = 'upload.html'
    form_class = ETL
    success_url = 'Home'defform_valid(self, form):
        url = self.request.get_full_path()
        form.process_data(url)

        returnsuper().form_valid(form)

and in the form:

class ETL(forms.Form):
    Historical = forms.FileField()
    Pre_processing = forms.FileField()
    Supplier = forms.FileField()
    parameters = forms.FileField()

    def process_data(self, url):
        dbschema = remove_www(url.split(':')[0]).lower()
        engine = create_engine('postgresql://pierre:56-Pmtmpmtm@127.0.0.1:5432/dbexostock12',
                               connect_args={'options': '-csearch_path={}'.format(dbschema)})

        fh = io.TextIOWrapper(self.cleaned_data['Historical'].file)
        fpp = io.TextIOWrapper(self.cleaned_data['Pre_processing'].file)
        fs = io.TextIOWrapper(self.cleaned_data['Supplier'].file)
        fp = io.TextIOWrapper(self.cleaned_data['parameters'].file)

Post a Comment for "Django : Error With Form_valid And Get_full_path()"