Trying to use views in django like I use to used in python
<p>why it does not work ?
It suppose to work, in python I can use this like this function, can any one explain me please ?</p>

<p><strong>views:</strong></p>

<pre><code>class MiVista(View):
    def get(self, request, var):
        self.var = 'Hello'
        # &lt;la logica de la vista&gt;
        return HttpResponse(self.var)

one = MiVista()
one.get(222222)
</code></pre>

<p><strong>urls:</strong></p>

<pre><code>url(r'^indice/', MiVista.as_view()),
</code></pre>

<p>So the functions does not work like function in python using POO ?</p>

<p>Thank you guys!</p>

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

<p>So basically you need to create <code>request</code> argument. You can do this with <a href="https://docs.djangoproject.com/en/1.10/topics/testing/advanced/#django.test.RequestFactory" rel="nofollow"><code>RequestFactory</code></a>. Like that</p>

<pre><code>from django.test import RequestFactory
from django.views.generic import View


class MiVista(View):
    def get(self, request, var):
        self.var = var
        # &lt;la logica de la vista&gt;
        return HttpResponse(self.var)

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

one = MiVista.as_view()(rf, var='hello')
</code></pre>

python django django-views