'DeferredAttribute'对象没有属性'startswith'

时间:2019-09-14 05:52:27

标签: python django

我不断收到此错误消息,不知道如何解决此问题。 当我使用存储的ID和密码登录时会显示此消息。

models.py

from __future__ import unicode_literals

from django.db import models

# Create your models here.

class seanyorder(models.Model):
    customer = models.ForeignKey('seany_user.seanyuser', on_delete=models.CASCADE, verbose_name='customer')
    product = models.ForeignKey('seany_product.seanyproduct', on_delete=models.CASCADE, verbose_name='product')


    def __str__(self):
        return str(self.customer) + ' ' + str(self.product)

    class Meta:
        db_table = 'seany_order'
        verbose_name = 'order'
        verbose_name_plural = 'order'

url.py

from django.conf.urls import url
from django.contrib import admin
from seany_user.views import index, registerview, loginview
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', index),
    url(r'^register/$', registerview.as_view()),
    url(r'^login/$', loginview.as_view())
]

view.py

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.views.generic.edit import FormView
from django.shortcuts import render
from seany_user.forms import registerform,loginform

# Create your views here.

def index(request):
    return render(request, 'index.html', { 'email': request.session.get('user') })

class registerview(FormView):
    template_name = 'register.html'
    form_class = registerform
    success_url = '/'

class loginview(FormView):
    template_name = 'login.html'
    form_class = loginform
    success_url = '/'

    def form_valid(self, form):
        self.request.session['customer'] = form.email

        return super().form_valid(form)

错误消息:

AttributeError at /login/
'DeferredAttribute' object has no attribute 'startswith'
Request Method: POST
Request URL:    http://127.0.0.1:8000/login/
Django Version: 2.2.5
Exception Type: AttributeError
Exception Value:    
'DeferredAttribute' object has no attribute 'startswith'
Exception Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/contrib/auth/hashers.py in is_password_usable, line 28
Python Executable:  /usr/local/bin/python3
Python Version: 3.7.4
Python Path:    
['/Users/seankang/Documents/Workspace/seanboy/nigro',
 '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
 '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
 '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']
Server time:    Sat, 14 Sep 2019 05:45:30 +0000

0 个答案:

没有答案