이이이이 https://github.com/yourcelf/django-registration-defaults/tree/master/registration_defaults/templates를 사용하는 나는 계획입니다 템플릿 내 views.pydjango에서 등록 템플릿을 만드는 중 오류가 발생했습니다. 디버깅하는 방법?
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})
내 forms.py
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
입니다.
그것은에 따르면, 나는 settings.py의 변화를했지만 그것은 나에게 오류
Error: Can't find the file 'settings.py' in the directory containing 'manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError somehow.)
은 그 템플릿을 사용하거나 내 자신의 사용자 정의 템플릿을 가야 좋은 생각을했다?
다른 간단한 질문이 있습니다. django 템플릿을 작성하는 방법 등록을 다룹니다. 사용자 이름, 비밀번호 및 이메일을 입력 할 수있는 템플릿을 제공합니다. 그게 다야 . 이것은 내 프로젝트에 너무 멋지다. – Hick