第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

注冊 - 序列項 0:預期的 str 實例,找到 NoneType

注冊 - 序列項 0:預期的 str 實例,找到 NoneType

慕田峪7331174 2023-09-02 16:12:52
Django 版本:3.0.8 - Python 版本:3.7.8我最近在 Django 網站上發(fā)現了一個錯誤。當用戶想要創(chuàng)建帳戶時,它會返回以下錯誤:序列項 0:預期的 str 實例,找到 NoneType手術:創(chuàng)建帳戶(檢查數據庫中是否尚不存在用戶名)創(chuàng)建用戶 Active = False發(fā)送一封電子郵件以確認帳戶創(chuàng)建。第一步出現錯誤,創(chuàng)建帳戶(Active = False),未發(fā)送電子郵件并顯示錯誤。Traceback (most recent call last):  File "/home/eodj89/virtualenv/DjangoPro/3.7/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner    response = get_response(request)  File "/home/eodj89/virtualenv/DjangoPro/3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response    response = self.process_exception_by_middleware(e, request)  File "/home/eodj89/virtualenv/DjangoPro/3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response    response = wrapped_callback(request, *callback_args, **callback_kwargs)  File "/home/eodj89/DjangoPro/user/views.py", line 45, in signup    user.save()  File "/home/eodj89/virtualenv/DjangoPro/3.7/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 66, in save    super().save(*args, **kwargs)  File "/home/eodj89/virtualenv/DjangoPro/3.7/lib/python3.7/site-packages/django/db/models/base.py", line 746, in save    force_update=force_update, update_fields=update_fields)  File "/home/eodj89/virtualenv/DjangoPro/3.7/lib/python3.7/site-packages/django/db/models/base.py", line 795, in save_base    update_fields=update_fields, raw=raw, using=using,  File "/home/eodj89/virtualenv/DjangoPro/3.7/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 175, in send    for receiver in self._live_receivers(sender)  File "/home/eodj89/virtualenv/DjangoPro/3.7/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 175, in <listcomp>    for receiver in self._live_receivers(sender)  File "/home/eodj89/DjangoPro/user/models.py", line 479, in create_user_profile    UserProfile.objects.create(user=instance)
查看完整描述

1 回答

?
阿波羅的戰(zhàn)車

TA貢獻1862條經驗 獲得超6個贊

讓我簡化一下您看到的錯誤:


In [1]: ''.join([None])

---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-1-29122f69a077> in <module>

----> 1 ''.join([None])


TypeError: sequence item 0: expected str instance, NoneType found

在您的情況下,您會在這一行得到相同的異常:


address = " ".join([self.full_address])

意思self.full_address就是None.


與此同時,我認為您不需要join那里,因為您嘗試連接單個字符串。您對這條線有何期望?


所以你的模型的代碼將如下所示:


class Profile(models.Model):

    user = models.OneToOneField(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)

    full_address = models.CharField(null=True,blank=True,max_length=128)

    latitude = models.DecimalField(max_digits=9, decimal_places=6, blank=True, default='0')

    longitude = models.DecimalField(max_digits=9, decimal_places=6, blank=True, default='0')

    slug = models.SlugField(editable=False)


    def save(self, *args,**kwargs):

        self.slug = slugify(self.user.username)

        

        if self.full_address:

            geo_code = geocoder.geocode(self.full_address)


            if geo_code:

                self.longitude = geo_code[0]['geometry']['lng']

                self.latitude  = geo_code[0]['geometry']['lat']

            

        super(Profile, self).save(*args, **kwargs)


查看完整回答
反對 回復 2023-09-02
  • 1 回答
  • 0 關注
  • 480 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號