Форум сайта python.su
Всем доброго времени суток, обращаюсь к вам за помощью.
Проблема такая: решил расширить юзера, добавил поле - nickname(поле выбрано в качестве тестового, суть в том, что бы просто научиться добавлять поля. какие - не важно):
#models.py
class UserProfile(models.Model): user = models.ForeignKey(User, unique=True, related_name='profile') nick_name = models.CharField(max_length=15)
class MyRegisterForm(UserCreationForm): print "OK!" nick_name = forms.CharField(max_length=30, required=True, widget=forms.TextInput) print "Ook" class Meta: model = UserProfile def save(self, commit=True): if not commit: raise NotImplementedError("Can't create User and UserProfile without database save") print "Saving..." user = super(MyRegisterForm, self).save(commit=False) user.nick_name = self.cleaned_data["nick_name"] user_profile = UserProfile(user=user, nick_name=self.cleaned_data['nick_name']) user_profile.save() print "Saving complete" return user, user_profile
def reg(request): if request.method =='POST': form = MyRegisterForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] print username password1 = form.cleaned_data['password1'] print password1 password2 = form.cleaned_data['password2'] print password2 nick_name = form.cleaned_data['nick_name'] print nick_name form.clean_username() if password1 == password2: new_user = form.save() return render_to_response('registration/registration_complete.html') else: print "Password error" return render_to_response('registration/registration_fail.html') else: print "FORM error" #ТУТ ВАЛИТСЯ :( return render_to_response('registration/registration_fail.html') else: form = UserCreationForm() # An unbound form return render_to_response('registration/registration_new_user.html', { 'form': form, },context_instance=RequestContext(request))
AUTH_PROFILE_MODULE = 'registration.UserProfile'
{% extends "base.html" %} {% block content %} <h1>Регистрация пользователя</h1> <form action="registration" method="post"> {% if form.error_dict %} <p class="error">Пожалуйста исправьте нижеприведённые ошибки.</p> {% endif %} {% if form.username.errors %} {{ form.username.html_error_list }} {% endif %} <label for="id_username">Логин:</label><br> {{ form.username }}<br> {% if form.password1.errors %} {{ form.password1.html_error_list }} {% endif %} <label for="id_password1">Пароль:</label><br> {{ form.password1 }}<br> {% if form.password2.errors %} {{ form.password2.html_error_list }} {% endif %} <label for="id_password2">Пароль (повторите):</label><br> {{ form.password2 }}<br> {% if form.nick_name.errors %} {{ form.nick_name.html_error_list }} {% endif %} <label for="id_nick_name">Пароль (повторите):</label><br> {{ form.nick_name }}<br> <br> <input type="submit" value="Зарегистрировать" /> </form> {% endblock %}
Офлайн
lov3catchFirst of all , what is error do you get
Помогите советом, пожалуйста.
lov3catchWe don't understand some words like: “ТУТ ” , could you please to submit more details about that error, if you'd like.
#ТУТ ВАЛИТСЯ :(
Отредактировано romankrv (Май 18, 2013 01:59:36)
Офлайн
lov3catchPlease, give us a traceback from here, if you have it., because there are 90% that allows us to get solution for fix.
Code crash in this plase.
Офлайн
Ok man, if you get some redirect than check your logic in there -
render_to_response - Is this function not work as you expect or what is going on there.
Maybe your form is not valid, please check it.
Luck for you.
Офлайн
Could you please to read django documentation about forms and how to deal with that. If you'd like because this is a first step is useful for you. Did you read about it early?
Luck
Отредактировано romankrv (Май 18, 2013 20:09:19)
Офлайн