This is the definition of NameError:
"Raised when a local or global name is not found. This applies only to
unqualified names. The associated value is an error message that
includes the name that could not be found."
I don't know what I doing wrong!
On Nov 8, 4:07 pm, "Alex Koshelev" <[EMAIL PROTECTED]> wrote:
> I think you have a typo in this line, May be you write `Image.new` with
> lowercase "L" not uppercase "I" as first char.
>
> On Sun, Nov 9, 2008 at 02:54, Tsinga <[EMAIL PROTECTED]> wrote:
>
> > Hi Djangonauts,
>
> > I need your help
>
> > I am trying to test a view using PIL(Python Imaging Library). This is
> > the code:
>
> > from django.http import HttpResponse, HttpResponseRedirect
> > from django.template import Context, RequestContext
> > from django.template.loader import get_template
> > from django.http import HttpResponse, Http404
> > from django.contrib.auth.models import User
> > from django.shortcuts import render_to_response
> > from django.contrib.auth import logout
> > from example_app.forms import *
> > from PIL import Image
> > import random
> > INK = "red", "blue", "green", "yellow"
>
> > def main_page(request):
> > return render_to_response(
> > 'main_page.html', RequestContext(request)
> > )
>
> > def user_page(request, username):
> > try:
> > user = User.objects.get(username=username)
> > except:
> > raise Http404('Requested user not found.')
>
> > bookmarks = user.bookmark_set.all()
> > variables = RequestContext(request, {
> > 'username': username,
> > 'bookmarks': bookmarks
> > })
> > return render_to_response('user_page.html', variables)
>
> > def logout_page(request):
> > logout(request)
> > return HttpResponseRedirect('/image/')
>
> > def register_page(request):
> > if request.method == 'POST':
> > form = RegistrationForm(request.POST)
> > if form.is_valid():
> > user = User.objects.create_user(
> > username=form.cleaned_data['username'],
> > password=form.cleaned_data['password1'],
> > email=form.cleaned_data['email']
> > )
> > return HttpResponseRedirect('/register/success/')
> > else:
> > form = RegistrationForm()
> > variables = RequestContext(request, {
> > 'form': form
> > })
> > return render_to_response(
> > 'registration/register.html', variables
> > )
>
> > def image_page(request):
> > """ create/load image here """
> > image = Image.new("RGB", (800, 600), random.choice(INK))
>
> > """ serialize to HTTP response """
> > response = HttpResponse(mimetype="image/png")
> > image.save(response, "PNG")
>
> > return response
>
> > I am having the following error:
>
> > Traceback:
> > File "/home/tsinga/webapps/django/lib/python2.5/django/core/handlers/
> > base.py" in get_response
> > 86. response = callback(request, *callback_args,
> > **callback_kwargs)
> > File "/home/tsinga/webapps/django/django_example/example_app/views.py"
> > in image_page
> > 57. image = Image.new("RGB", (800, 600), random.choice(INK))
>
> > Exception Type: NameError at /image/
> > Exception Value: global name 'Image' is not defined
>
> > Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---