2011-06-11 2 views
0

이이이이 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.) 

은 그 템플릿을 사용하거나 내 자신의 사용자 정의 템플릿을 가야 좋은 생각을했다?

답변

0

프로젝트에 가져 오기 문제가 있다고 생각합니다. 그러나 장고가이 문제를 발견하고 실제 오류를 표시하지는 않습니다. 이 설정은 settings.py에서 가져올 필요가 없습니다. 프로젝트의 아무 곳이나 가져올 수 있습니다.

시도 실행 :

python settings.py 

그리고 파이썬 가져 오기 문제가 무엇인지를 알려 주어야합니다. 산출물이 없다면 다른 곳에 문제가 있습니다. 그러나 이것은 매우 가능성있는 후보입니다.

+0

다른 간단한 질문이 있습니다. django 템플릿을 작성하는 방법 등록을 다룹니다. 사용자 이름, 비밀번호 및 이메일을 입력 할 수있는 템플릿을 제공합니다. 그게 다야 . 이것은 내 프로젝트에 너무 멋지다. – Hick

1

와우, 어떤 장고 버전을 사용하고 계십니까? forms.Manipulator은 버전 1.0에서 3 년 전에 삭제되었으며 이전 버전에서는 사용되지 않았습니다.

관련 문제