2

I'm hitting a wall with this error. I'm sure I'm overlooking something basic, just can't seem to figure it out...

ValueError at /sing/register

The view sing.singer.views.grade didn't return an HttpResponse object.

the view file...

from django.shortcuts import render_to_response
from django import forms
from django.http import HttpResponseRedirect
from django.template import Template, RequestContext
from dash.forms import GradeForm


def register(request):
    if request.method == 'POST':
        form = GradeForm(data=request.POST)
        if form.is_valid():
            new_dash_profile = form.save()
            new_user = form.save()
            return  HttpResponseRedirect("/success/")
        else:
            form = RegisterForm()
        return render_to_response('grade.html',{'form':form},context_instance=RequestContext(request) )

my urls.py

urlpatterns = patterns('dashboard.dash.views',
 (r'^sing/register','register' ),)

my settings.py

TEMPLATE_DIRS = (
    "/home/django/testing/sing/grade/templates",)

3 Answers 3

4
def register(request):
    if request.method == 'POST':
        form = GradeForm(data=request.POST)
        if form.is_valid():
            new_dash_profile = form.save()
            new_user = form.save()
            return  HttpResponseRedirect("/success/")
    else:
        form = RegisterForm()
    return render_to_response('grade.html',{'form':form},context_instance=RequestContext(request) )

your indents look off?

Initially you are entering the view with request != 'POST' which will never reach that else statement at the bottom, so you dont get a HttpResponse.

The other thing that looks strange is even if you fix your indents, you show the RegisterForm initially, and after the post request, you put the data from your RegisterForm into a GradeForm, if that doesn't validate you show pass your GradeForm to your template. Is this what you intended?

also in your urls.py I would add / to:

(r'^sing/register','register' ),)

like:

(r'^sing/register/','register' ),)

unless you want it to match (for example):

www.site.com/sing/registerasdf/

i might even suggest using '/$' at the end like this:

(r'^sing/register/$','register' ),)

to prevent matches to (for example):

www.site.com/sing/register/asdf/asdf/asdf/
www.site.com/sing/register/asdf/asdf/
www.site.com/sing/register/asdf/
Sign up to request clarification or add additional context in comments.

1 Comment

wow. it was the indenting indeed! total blonde moment! Thanks @DTing!
1

Judging from the code, the only time it does not return a HttpResponse is when it's not a POST request. Maybe you are doing a GET instead?

Comments

0

I think its your HttpResonseRedirect. I can't say I've used it that often (if at all). If I were you I would try shortcut redirect

http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect

4 Comments

@DTing Thats interesting and I'm not sure what you were trying to say.
Sorry, since hes just passing an URL there's no reason for him to use the redirect shortcut.
@DTing You're probably right!.. I also didn't notice the indenting you pointed out that would make a difference. I just happen to like the shortcuts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.