Re: CBVs and logging a user
my URLS_CONF points to my urls.py in my main project directory. The error only once I press the login button, the form is validated, the user then(correctly ) is authenticated then it fails with the error when I try to redirect it to a view.
On Monday, June 3, 2013 2:45:09 PM UTC, tony gair wrote:
--I'm getting an errorDjango Version: 1.5.1Exception Type: ImproperlyConfiguredException Value:The included urlconf main.urls doesn't have any patterns in itmy login form and view has been modified to work off email and password rather than username and passwordmy forms.py looks likeclass MyCustomLoginForm(forms.Form):"""A login form for the customer model"""email = forms.EmailField(label=('Your email address'),required=True)password = forms.CharField(label=('Your password'),widget=forms.PasswordInput,required=True)def clean(self):"""If the user is valid and active then auth them & return the clean_data"""clean_data = self.cleaned_datatry:# authenticate the detailsuser = authenticate(username=clean_data['email'],password=clean_data['password']) if user and user.is_active:self.user = userreturn clean_dataexcept (KeyError, AttributeError):passraise forms.ValidationError(('Incorrect Password')) views.py looks likeclass LoginView(FormView):"""Give a view to login"""form_class = MyCustomLoginFormtemplate_name = 'login.html'success_url = reverse ('orglv')def get_success_url(self):return reverse ('orglv')def form_valid(self, form):""" if the form is valid, then log the user in"""login(self.request, form.user)return HttpResponseRedirect(self.get_success_url()) backends.py looks likeclass EmailOrUsernameModelBackend(object): def authenticate(self, username=None, password=None):print(username)print(password)try:user = Heating_User.objects.get(email=username) print(user.username)print(user.password)if user.check_password(password):print("password ok")return userexcept Heating_User.DoesNotExist:print("crap")return Nonedef get_user(self, user_id):try:return Heating_User.objects.get(pk=user_id) except User.DoesNotExist:return Noneand my login.html looks like{% extends "base.html" %}{% block title %}Login{% endblock title %}{% block content %}<form method="post">{% csrf_token %}{{ form.as_p }}<button type="submit" >login</button><input type="hidden" name="next" value="{{next}}" /></form>{% endblock content %}and my urls.py looks likeurlpatterns = patterns('',url(regex=r'login/$',view=LoginView.as_view(),name="login"),has anyone any ideas?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home