我正在用 python 和 django 制作一个测试项目(用于学习目的)。在某些时候,我必须制作一个名为 products 的 django 应用程序,然后在“products”应用程序目录中的 models.py 文件中,我有以下代码:
class Products (models.Model)
title = models.TextField()
description = models.TextField()
price = models.TextField()
然后在我参加迁移时在设置文件中添加新应用程序后,如图所示:
> python manage.py makemigrations
我得到的是这个错误:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\django\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:\django\lib\site-packages\django\core\management\__init__.py", line 347, in execute
django.setup()
File "C:\django\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\django\lib\site-packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\django\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\django\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 724, in exec_module
File "<frozen importlib._bootstrap_external>", line 860, in get_code
File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\django\mystore\products\models.py", line 5
class Products(models.Model)
^
SyntaxError: invalid syntax
"
然后每当我尝试使用 manage.py 文件时都会发生相同的错误。我不知道我做错了什么,请帮我解决这个问题。