클래스 기반 제네릭 뷰를 사용하여 reg/auth/auth를 도와 줄 수 있습니까? 함수 기반 뷰에서는이를 수행하는 방법이 분명하지만 클래스에서는 그렇지 않습니다. 양식을 렌더링 할 때 CBV의 철학을 이해할 수 없습니다.django에 클래스 기반 제네릭 뷰가있는 등록/승인 양식
1
A
답변
1
기능보기와 잘 작동하면 클래스 기반이어야하는 이유는 무엇입니까?
class SignUpFormView(FormView):
form_class = SignUpForm
template_name = 'authentication/registration_form.html'
def form_valid(self, form):
""" What to do with the valid form ?
- Create the user and a default website
- Send a mail to confirm the email and the account creation
"""
user = User.objects.create_user(form.cleaned_data['username'],
form.cleaned_data['email'],
form.cleaned_data['password'])
user.is_active = False
user.save()
date = user.date_joined.replace(microsecond=0)
key = hashlib.sha1((u'%s%s%s' % (settings.SECRET_KEY, user.email, date)
).encode('utf-8')).hexdigest()
subject = _(u'[%s] : Subscription') % settings.SITE_NAME
mail = render_to_string('authentication/mails/registration_confirmation.html',
{ 'titre': subject,
'pseudo': user.username,
'site': settings.SITE_NAME,
'user_id': user.id,
'user_key': key })
msg = EmailMessage(subject, mail, '%(site)s <%(email)s>' % {
'site': settings.SITE_NAME, 'email': settings.DEFAULT_FROM_EMAIL
}, [user.email])
msg.content_subtype = "html" # Main content is now text/html
try:
msg.send()
except:
# In debug we display the url
print reverse('auth_activation', args=[user.id, key])
return render_to_response("authentication/check_your_mail.html",
context_instance=RequestContext(self.request))
당신이 명시 적으로 당신이 정확하게 수행 할 수행 할 수 있습니다 등록
나는이 사용? – Natim
내 자신의 클래스 기반보기를 사용하여 권한 및 등록 양식을 만들고 싶습니다. – megido
그래서 기본적으로 두 클래스가 필요합니까? 다른 하나는 인증을 위해 등록 하시겠습니까? – Natim