‘function’对象没有属性’_meta’inlineformset_factory django

'function' object has no attribute '_meta' inlineformset_factory django

我正在尝试创建一个提交带有外键的模型的表单,但出现了以下错误:

Traceback (most recent call last):
File"C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
response = get_response(request)
File"C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File"C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File"C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\views\decorators\csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File"~.py", line 21, in wrap
return function(request, *args, **kwargs)
File"~.py", line 32, in wrap
return function(request, *args, **kwargs)
File"~.py", line 428, in example
PostFormSet = inlineformset_factory(User, Post, fields=('longitude', 'latitude', 'placename', 'explanation', ))
File"C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\forms\models.py", line 1038, in inlineformset_factory
fk = _get_foreign_key(parent_model, model, fk_name=fk_name)
File"C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\forms\models.py", line 980, in _get_foreign_key
opts = model._meta
AttributeError: 'function' object has no attribute '_meta'

型号.py

1
2
3
4
5
6
class Post(models.Model):
      owner = models.ForeignKey(User,on_delete=models.CASCADE,related_name="posts",blank=False,null=False)
      </other fields>...

class PostImage(models.Model):
      owner = models.ForeignKey(Post,on_delete=models.CASCADE,related_name="images",blank=False,null=False)

视图.py

1
2
3
4
5
6
7
8
9
def example(request):
    context = {
        'hellow we':"qfqf"
    }
    print(request.user)
    PostFormSet = inlineformset_factory(User, Post, fields=('longitude', 'latitude', 'placename', 'explanation', ))
    print("------------------------------------------------------------")
    print(frm.errors)
    return JsonResponse(context, encoder=JSONEncoder)


我发现的问题。有另一个名叫邮件功能的观点