Re: IntegrityError at /register/ auth_user.username may not be NULL
On Mar 28, 9:38 pm, Daniel Roseman wrote: > On Wednesday, 28 March 2012 20:31:09 UTC+1, laurence Turpin wrote: > > > I'm getting the following error with my registration section of my > > program. > > > IntegrityError at /register/ > > auth_user.username may not be NULL > > > I am using django 1.3.1 and python 2.7.2 and I'm using sqlite3 as the > > database. > > I am a newbie and I'm learning Djanogo from the book "Learning website > > development with Django" > > > The registration form is displayed ok and I'm able to fill it out and > > it is when I click register that the problem occurs. > > > /// > > /// > > / > > > My views.py looks like the following and register_page is the > > relevant function here: > > > > > > def clean_username(self): > > username = self.cleaned_data['username'] > > if not re.search(r'^\w+$', username): > > raise forms.ValidationError('Username can only contain > > alphanumeric characters and underscores') > > try: > > User.objects.get(username=username) > > except ObjectDoesNotExist: > > return username > > raise forms.ValidationError('Username already taken. ') > > Looks like you have an indentation problem in clean_username - the lines > under the first "raise forms.ValidationError" should be one level to the > left, otherwise they will never be reached and the method will never return > the cleaned value for username. > -- > DR. Thank you Danial you are absolutely right. I tried what you said and it works fine now. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: IntegrityError at /register/ auth_user.username may not be NULL
On Wednesday, 28 March 2012 20:31:09 UTC+1, laurence Turpin wrote: > > I'm getting the following error with my registration section of my > program. > > IntegrityError at /register/ > auth_user.username may not be NULL > > I am using django 1.3.1 and python 2.7.2 and I'm using sqlite3 as the > database. > I am a newbie and I'm learning Djanogo from the book "Learning website > development with Django" > > The registration form is displayed ok and I'm able to fill it out and > it is when I click register that the problem occurs. > > /// > > > > My views.py looks like the following and register_page is the > relevant function here: > > > > def clean_username(self): > username = self.cleaned_data['username'] > if not re.search(r'^\w+$', username): > raise forms.ValidationError('Username can only contain > alphanumeric characters and underscores') > try: > User.objects.get(username=username) > except ObjectDoesNotExist: > return username > raise forms.ValidationError('Username already taken. ') > Looks like you have an indentation problem in clean_username - the lines under the first "raise forms.ValidationError" should be one level to the left, otherwise they will never be reached and the method will never return the cleaned value for username. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/sXr3JbbnrqcJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
IntegrityError at /register/ auth_user.username may not be NULL
I'm getting the following error with my registration section of my program. IntegrityError at /register/ auth_user.username may not be NULL I am using django 1.3.1 and python 2.7.2 and I'm using sqlite3 as the database. I am a newbie and I'm learning Djanogo from the book "Learning website development with Django" The registration form is displayed ok and I'm able to fill it out and it is when I click register that the problem occurs. /// My views.py looks like the following and register_page is the relevant function here: /// from django.http import Http404 from django.contrib.auth.models import User from django.shortcuts import render_to_response from django.http import HttpResponseRedirect from django.contrib.auth import logout from django.template import RequestContext from bookmarks.bookmarksapp.forms import RegistrationForm def main_page(request): return render_to_response( 'main_page.html', RequestContext(request) ) def user_page(request, username): try: user = User.objects.get(username=username) except: raise Http404('Requested user not found') bookmarks = user.bookmark_set.all() variables = RequestContext(request, { 'username': username, 'bookmarks': bookmarks }) return render_to_response('user_page.html', variables) def logout_page(request): logout(request) return HttpResponseRedirect('/') def register_page(request): if request.method =='POST': form = RegistrationForm(request.POST) if form.is_valid(): form.user = User.objects.create_user( username = form.cleaned_data['username'], password = form.cleaned_data['password1'], email = form.cleaned_data['email'] ) return HttpResponseRedirect('/register/success/') else: form = RegistrationForm() variables = RequestContext(request, { 'form': form }) return render_to_response( 'registration/register.html', variables ) /// My forms.py is the following: /// from django import forms import re from django.contrib.auth.models import User from django.core.exceptions import ObjectDoesNotExist class RegistrationForm(forms.Form): username = forms.CharField(label="Username", max_length=30) email = forms.EmailField(label='Email') password1 = forms.CharField( label='Password', widget=forms.PasswordInput() ) password2 = forms.CharField( label='Password', widget=forms.PasswordInput() ) def clean_password2(self): if 'password1' in self.cleaned_data: password1 = self.cleaned_data['password1'] password2 = self.cleaned_data['password2'] if password1 == password2: return password2 raise forms.ValidationError('Passwords do not match.') def clean_username(self): username = self.cleaned_data['username'] if not re.search(r'^\w+$', username): raise forms.ValidationError('Username can only contain alphanumeric characters and underscores') try: User.objects.get(username=username) except ObjectDoesNotExist: return username raise forms.ValidationError('Username already taken. ') /// my register.html looks like the following: /// {% extends "base.html" %} {% block title %}User Registration{% endblock %} {% block head %}User Registration{% endblock %} {% block content %} {% csrf_token %} {{ form.as_p }} {% endblock %} ///