NoneType没有属性“json_string”

2024-09-27 19:21:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我会保持简短,因为我在过去的帖子中运气不好。我正在建立一个网站,使用羽毛笔文本编辑器(不重要),并将文本保存到一个数据库,以后可以用来编辑。当我运行“python manage.py runserver”时,我的本地托管服务器上的一切都运行得很好。然而,当我在Heroku上运行它来在线托管它时,我得到了这个错误

Request Method: GET
Request URL:    https://vast-river-12269.herokuapp.com/signup/new_search/posts/create/
Django Version: 3.1.2
Exception Type: AttributeError
Exception Value:    
'NoneType' object has no attribute 'json_string'
Exception Location: /app/.heroku/python/lib/python3.6/site-packages/django_quill/forms.py, line 17, 
in 
prepare_value
Python Executable:  /app/.heroku/python/bin/python
Python Version: 3.6.13
Python Path:    
['/app/.heroku/python/bin',
 '/app',
 '/app/.heroku/python/lib/python36.zip',
 '/app/.heroku/python/lib/python3.6',
 '/app/.heroku/python/lib/python3.6/lib-dynload',
 '/app/.heroku/python/lib/python3.6/site-packages']

它在NoneType中表示没有属性json_字符串,这似乎非常通用。我也没有在我的项目中使用json,我在任何地方都看不到它。不过,我已将问题缩小到一行代码。在我的HTML中,我有一行调用变量“{forms.content}”。这一行就是问题所在,它与下面的models.py文件和forms.py文件相关。它们附在下面,但我在那里找不到任何问题,它在我的本地主机上工作,所以我不明白

我想知道的是这篇文章

  • 如何解决这个问题
  • 为什么会发生这个问题

模型。py

from django.db import models
from django.contrib.auth.models import AbstractUser, UserManager
from django.conf import settings
User = settings.AUTH_USER_MODEL
from django.conf import settings
from django.urls import reverse
from django_quill.fields import QuillField


# Create your models here.


class QuillPost(models.Model):
    content = QuillField()

    class Meta:
        ordering = ['-pk']

    def get_absolute_url(self):
        return reverse('quill-post-detail', args=[self.pk])




class Text(models.Model):
    document = models.CharField(max_length=100)

    def __str__(self):
        return self.document

class CustomUserManager(UserManager):
    pass


class CustomUser(AbstractUser):
    objects = CustomUserManager()

class Search(models.Model):
    #user = models.ForeignKey(User, on_delete=models.CASCADE)
    search = models.CharField(max_length=500)
    created = models.DateTimeField(auto_now=True)

    def __str__(self):
        return '{}'.format(self.search)

    class Meta:
        verbose_name_plural = 'Searches'

表单。py

from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import CustomUser
from .models import Text
from django_quill.forms import QuillFormField
from .models import QuillPost


class QuillForm(forms.Form):
    quill = QuillFormField()



class QuillFieldForm(forms.Form):
    content = QuillFormField()

    def save(self):
        return QuillPost.objects.create(content=self.cleaned_data['content'])


class QuillPostForm(forms.ModelForm):
    class Meta:
        model = QuillPost
        fields = ['content']

很抱歉发了这么长的帖子,但我真的需要帮助


Tags: djangofrompyimportselfappherokumodels

热门问题