On Jul 3, 8:38 am, Geoff <g...@geoff.kelsall.name> wrote:
> Dear Django users,
>
> I am writing my first Django application (also new to Python and have
> not done any web programming for many years) and am trying to produce
> a screen which allows a row to be added to a table (I know this can be
> done in admin but once I have it working I will add more features).
> But I am getting:
>
> AttributeError at /forum/gktest/
> 'WSGIRequest' object has no attribute 'gk'
<snip>
> def gktest_save_page(request):
>   if request.method == 'POST':
>       # Creating a form to add a submission.
>     form = GKtestForm(request.POST)
>
>     if form.is_valid():
>         gktest, created = GKtest.objects.get_or_create(
>         gk = request.gk
>               )
>         gktest.save()
>         return HttpResponseRedirect(
>           '/gktest/'
>       )
>   else:
>     form = GKtestForm()
>   variables = RequestContext(request, {
>     'form': form
>   })
>   return render('gktest_save.html', variables)
>
<snip>
> Presumably I have missed out something elementary? Any hints
> gratefully received.
>

Er, yes. As the traceback says, request doesn't have a 'gk' attribute.
What makes you think it should? gk is a field on the form, and there
is a corresponding member of request.POST if the field has been filled
in and submitted.

You could use request.POST['gk'], but since you're using a ModelForm,
you don't need to do any of that - just call form.save(), and that
will return a properly saved GKtest instance.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to