name 'request' is not defined

2,460 views
Skip to first unread message

nash

unread,
Nov 10, 2009, 2:34:24 PM11/10/09
to Django users
hi i have defined a function in my view.py

from django.http import HttpResponse

class work(request):
def get(self):
return HttpResponse("its working")

but when i browse to mysite/work i am getting "name 'request' is not
defined" any one have any idea what is wrong ?
cheers nash

Daniel Roseman

unread,
Nov 10, 2009, 3:07:55 PM11/10/09
to Django users
Yes: you need to learn some Python. What you've written is a class
that inherits from 'request', with a 'get' method. 'request' is not a
parameter here, so it has to exist in the module somewhere.

What are you trying to do?
--
DR.

nash

unread,
Nov 10, 2009, 4:32:03 PM11/10/09
to Django users
hi thanks for the reply i am trying to get django up and running with
googleapp engine as. i understand in django correct me if i am wrong
return is a global variable when a url is matched as defined in the
url.py it calls the class that is matched in views.py and all the
variables are passed in request object. so i am bit confused why i am
getting the error. have i miss configured some thing some how ? below
is my urls.py if its any help

from django.conf.urls.defaults import *
from portfolio.models import Project

info_dict = {
'queryset': Project.all()
}
urlpatterns = patterns('',
# Example:
# (r'^foo/', include('foo.urls')),
(r'^work/$', 'portfolio.views.work'),
# Uncomment this for admin:
# (r'^admin/', include('django.contrib.admin.urls')),
)

Daniel Roseman

unread,
Nov 10, 2009, 4:46:50 PM11/10/09
to Django users
On Nov 10, 9:32 pm, nash <nash.raf...@gmail.com> wrote:
> hi thanks for the reply i am trying to get django up and running with
> googleapp engine as. i understand in django correct me if i am wrong
> return is a global variable when a url is matched as defined in the
> url.py it calls the class that is matched in views.py and all the
> variables are passed in request object. so i am bit confused why i am
> getting the error. have i miss configured some thing some how ?  below
> is my urls.py if its any help
>

But where did you get the idea that it should be a class? As I said
(probably a bit more harshly than I intended), this is basic Python:
when you do 'class work(request)' that doesn't mean a function to
which you pass 'request', it means a class that inherits from
'request', which must already be defined in that scope. This is
absolutely not what you want. And why define a 'get' method?

Just get rid of the class, and do as the documentation says: a simple
function that takes the 'request' parameter and returns a response.

def work(request):
return HttpResponse("it's working")
--
DR.
Reply all
Reply to author
Forward
0 new messages