在django中创建注册模板时出错。如何调试?

在django中创建注册模板时出错。如何调试?,django,Django,这是我的表格 from django import forms from django.core import validators from django.contrib.auth.models import User class RegistrationForm(forms.Manipulator): def __init__(self): self.fields = ( forms.TextField(field_name='usernam

这是我的表格

from django import forms
from django.core import validators
from django.contrib.auth.models import User

class RegistrationForm(forms.Manipulator):
    def __init__(self):
        self.fields = (
            forms.TextField(field_name='username',
                            length=30, maxlength=30,
                            is_required=True, validator_list=[validators.isAlphaNumeric,
                                                              self.isValidUsername]),
            forms.EmailField(field_name='email',
                             length=30,
                             maxlength=30,
                             is_required=True),
            forms.PasswordField(field_name='password1',
                                length=30,
                                maxlength=60,
                                is_required=True),
            forms.PasswordField(field_name='password2',
                                length=30, maxlength=60,
                                is_required=True,
                                validator_list=[validators.AlwaysMatchesOtherField('password1',
                                                                                   'Passwords must match.')]),
            )

    def isValidUsername(self, field_data, all_data):
        try:
            User.objects.get(username=field_data)
        except User.DoesNotExist:
            return
        raise validators.ValidationError('The username "%s" is already taken.' % field_data)

    def save(self, new_data):
        u = User.objects.create_user(new_data['username'],
                                     new_data['email'],
                                     new_data['password1'])
        u.is_active = False
        u.save()
        return u
这是我的观点

from django.contrib.auth import authenticate, login
from django.shortcuts import render_to_response

import datetime, random, sha
from django.shortcuts import render_to_response, get_object_or_404
from django.core.mail import send_mail





def login(request):
    def errorHandle(error):
        form = LoginForm()
        return render_to_response('login.html', {
                'error' : error,
                'form' : form,
        })
    if request.method == 'POST': # If the form has been submitted...
        form = LoginForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    # Redirect to a success page.
                    login(request, user)
                    return render_to_response('userprof/why.html', {
                        'username': username,
                    })
                else:
                    # Return a 'disabled account' error message
                    error = u'account disabled'
                    return errorHandle(error)
            else:
                 # Return an 'invalid login' error message.
                error = u'invalid login'
                return errorHandle(error)
        else:
            error = u'form is invalid'
            return errorHandle(error)
    else:
        form = LoginForm() # An unbound form
        return render_to_response('login.html', {
            'form': form,
        })



def loggedin(request):

    return render_to_response('loggedin.html', {})


def register(request):
    if request.user.is_authenticated():
        # They already have an account; don't let them register again
        return render_to_response('userprof/register.html', {'has_account': True})
    manipulator = RegistrationForm()
    if request.POST:
        new_data = request.POST.copy()
        errors = manipulator.get_validation_errors(new_data)
        if not errors:
            # Save the user                                                                                                                                                 
            manipulator.do_html2python(new_data)
            new_user = manipulator.save(new_data)

            # Build the activation key for their account                                                                                                                    
            salt = sha.new(str(random.random())).hexdigest()[:5]
            activation_key = sha.new(salt+new_user.username).hexdigest()
            key_expires = datetime.datetime.today() + datetime.timedelta(2)

            # Create and save their profile                                                                                                                                 
            new_profile = UserProfile(user=new_user,
                                      activation_key=activation_key,
                                      key_expires=key_expires)
            new_profile.save()

            # Send an email with the confirmation link                                                                                                                      
            email_subject = 'Your new example.com account confirmation'


            return render_to_response('userprof/register.html', {'created': True})
    else:
        errors = new_data = {}
    form = forms.FormWrapper(manipulator, new_data, errors)
    return render_to_response('userprof/register.html', {'form': form})


def confirm(request, activation_key):
    if request.user.is_authenticated():
        return render_to_response('userprof/confirm.html', {'has_account': True})
    user_profile = get_object_or_404(UserProfile,
                                     activation_key=activation_key)
    if user_profile.key_expires < datetime.datetime.today():
        return render_to_response('confirm.html', {'expired': True})
    user_account = user_profile.user
    user_account.is_active = True
    user_account.save()
    return render_to_response('confirm.html', {'success': True})

使用这些模板是个好主意,还是我应该使用自己的自定义模板?

我猜您的项目存在导入问题-但Django捕捉到了这一点,并没有向您显示真正的错误。请注意,这不需要是从settings.py导入-它可以是项目中任何位置的导入

尝试运行:

python settings.py

python应该告诉您什么是导入问题。如果没有输出,您的问题就出在其他地方-但这很可能是一个候选对象。

哇,您使用的是什么版本的Django<代码>表单.操纵器在三年前的1.0版中被删除,在那之前的一年中被弃用。

我还有一个简单的问题。如何编写处理注册的django模板。提供一个模板,我可以在其中输入用户名、密码和电子邮件。就这些。这对我的项目来说太花哨了
python settings.py