Click here to Skip to main content
15,885,195 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
please, I need help with that "request" object that is making me despair...

I read that theoretically "request" in views is an "HttpRequest" object but I have a script which needs to call a views.py function, which needs to use that "request" so receive it as argument.

Then I tried to import that object in my script in so many modes, but it seems always "not be the same" and I get annoying errors as:
"'HttpRequest' object has no attribute 'session'"

Is there another way to use "request" object in a view's function avoiding to pass as argument?
Something like this:?

Python
def view_function():
    request = ??
    form = fooform
    bar = request.session['foo']
    context{
    'form' = form
    'bar' = bar
    }
    return render(request, "foo.html", context)


I know that's not elegant, but I'm still learning and I really don't need for this program an elegant solution.
Thanks in advance

What I have tried:

I tried to import that misterious object in so many modes:

Python
from django.http import request

,
Python
from django.http import HttpRequest
request = HttpRequest()

,
Python
from urllib import request

,
Python
from urllib import HttpRequest

,
Python
import django.http.request

...
Posted
Updated 13-Aug-16 2:22am

1 solution

I fixed it! I realised that I forgot to pass the "request" parameter when I call my script main funcion. That's why my external script "didn't know" what "request" was.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900