1

このエラーが発生しています。多くの作業を試みましたが、何が問題なのか理解できません。私は基本的に、いくつかのフォームに記入するサインアップ登録をしようとしています

Request Method: GET
Request URL:    http://127.0.0.1:8000/gi/
Django Version: 1.5.1
Exception Type: NameError
Exception Value:    
global name 'HttpRequestRedirect' is not defined
Exception Location: /home/xx/Desktop/GoAmma/vendorAmmma/vreg/views.py in GIRegistration, line 42
Python Executable:  /home/xx/Desktop/forfte/bin/python
Python Version: 2.7.3

ビューは次のようになります。

# Create your views here.
from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.template import RequestContext
from vreg.forms import RegistrationForm, LoginForm
from vreg.models import Vendor
from django.contrib.auth import authenticate, login, logout

def VendorRegistration(request):
    if request.user.is_authenticated():
        return HttpRequestRedirect('/profile/')
    if request.method=='POST':
        form= RegistrationForm(request.POST)
        if form.is_valid():
            user=User.objects.create_user(username=form.cleaned_data['username'], email= form.cleaned_data['emailadd'], password= form.cleaned_data['password'])
            user.save()
            vreg=Vendor(user=user)
            vreg.save()
            return HttpResponseRedirect('/profile/')
        else:
            return render_to_response('register.html', {'form':form}, context_instance=RequestContext(request))

    else:
        ''' user is not submitting form show them blank registration form'''
        form= RegistrationForm()
        context={'form':form}
        return render_to_response('register.html', context, context_instance=RequestContext(request))

@login_required
def Profile(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login/')
    vreg= request.user.get_profile
    context={'vreg':vreg}
    return render_to_response('profile.html',context,context_instance=RequestContext(request))  

@login_required 
def GIRegistration(request):
    if request.user.is_authenticated():
        return HttpRequestRedirect('/profile/')
    if request.method=='POST':
        form= GIForm(request.POST)
        if form.is_valid():
            contact = form.save()
            contact.save()
            return HttpResponseRedirect('/profile/')
        else:
            return render_to_response('generalinfo.html', {'form':form}, context_instance=RequestContext(request))

    else:
        ''' user is not submitting form show them blank registration form'''
        form= GIForm()
        context={'form':form}
        return render_to_response('generalinfo.html', context, context_instance=RequestContext(request))

def LoginRequest(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/profile/')
    if request.method=='POST':
        form=LoginForm(request.POST)
        if form.is_valid():
            username=form.cleaned_data['username']
            password=form.cleaned_data['password']
            vreg= authenticate(username=username,password=password)
            if vreg is not None:
                login(request,vreg)
                return HttpResponseRedirect('/profile/')
            else:
                return render_to_response('login.html',{'form':form}, context_instance= RequestContext(request))
        else:
            return render_to_response('login.html',{'form':form}, context_instance= RequestContext(request))

    else:
        '''user not submitting form show the login form'''
        form= LoginForm()
        context={'form': form}
        return render_to_response('login.html',context,context_instance= RequestContext(request))

def LogoutRequest(request):
    logout(request)
    return HttpResponseRedirect('/')
4

1 に答える 1

5

そうHttpResponseRedirectではありませんHttpRequestRedirect

return HttpRequestRedirect('/profile/')これをに変更return HttpResponseRedirect('/profile/')

PSコードでハードコーディングされたURLを使用しないでください。URLの逆解決を使用してください

于 2013-06-11T11:15:41.527 に答える