[Fixed]-Trying to use views in django like I use to used in python

1👍

So as @MadWombat mentioned, you are not passing enough arguments, so you need to pass self, which already passing by calling from instance objects, request(not passing), var(passing). And as you are not providing that you are passing var=2222, python thinks that 2222 is request argument.

So basically you need to create request argument. You can do this with RequestFactory. Like that

from django.test import RequestFactory
from django.views.generic import View


class MiVista(View):
    def get(self, request, var):
        self.var = var
        # <la logica de la vista>
        return HttpResponse(self.var)

rf = RequestFactory()
rf.get('indice/')

one = MiVista.as_view()(rf, var='hello')

Leave a comment