django语法无效



我正在尝试运行一个django代码,一个我制作的imx6-yocto构建。基本的例子做得很顺利。所以我决定从我正在工作的一个项目中运行我自己的django制作,我得到了以下内容:

root@imx6ulevk:/home/mdwb-main# python manage.py runserver 147.106.17.9:8000  
Watching for file changes with StatReloader  
Exception in thread django-main-thread:  
Traceback (most recent call last):  
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner  
self.run()  
File "/usr/lib/python3.5/threading.py", line 862, in run  
self._target(*self._args, **self._kwargs)  
File "/usr/lib/python3.5/site-packages/django/utils/autoreload.py", line 54, in wrapper  
fn(*args, **kwargs)  
File "/usr/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 109, in   inner_run  
autoreload.raise_last_exception()  
File "/usr/lib/python3.5/site-packages/django/utils/autoreload.py", line 77, in   raise_last_exception  
raise _exception[1]  
File "/usr/lib/python3.5/site-packages/django/core/management/__init__.py", line 337, in execute  
autoreload.check_errors(django.setup)()  
File "/usr/lib/python3.5/site-packages/django/utils/autoreload.py", line 54, in wrapper  
fn(*args, **kwargs)  
File "/usr/lib/python3.5/site-packages/django/__init__.py", line 24, in setup  
apps.populate(settings.INSTALLED_APPS)  
File "/usr/lib/python3.5/site-packages/django/apps/registry.py", line 114, in populate  
app_config.import_models()  
File "/usr/lib/python3.5/site-packages/django/apps/config.py", line 211, in import_models  
self.models_module = import_module(models_module_name)  
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module  
return _bootstrap._gcd_import(name[level:], package, level)  
File "<frozen importlib._bootstrap>", line 985, in _gcd_import  
File "<frozen importlib._bootstrap>", line 968, in _find_and_load  
File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked  
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked  
File "<frozen importlib._bootstrap_external>", line 693, in exec_module  
File "<frozen importlib._bootstrap_external>", line 799, in get_code  
File "<frozen importlib._bootstrap_external>", line 759, in source_to_code  
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed  
File "/home/mdwb-main/api_cloud/models.py", line 15  
return f'{self.cloud_interval} foi cadastrado com sucesso!'  
^  
SyntaxError: invalid syntax  

models.py中的代码如下:

from django.db import models
# Create your models here.
class Initial_config(models.Model):
#complement = models.CharField(max_length=30,null=True)
cloud_interval = models.IntegerField()
device_interval = models.IntegerField()
class Meta:
verbose_name = 'config'
verbose_name_plural = 'configs'
def __str__(self):
return f'{self.cloud_interval} foi cadastrado com sucesso!'

我试图将">更改为">删除{self.cloud_interval},但没有一个成功
为什么会发生这种情况?如何修复?

f-strings只能从Python 3.6开始使用。

如果您想继续使用Python 3.5,可以将代码更改为:

def __str__(self):
return '%s foi cadastrado com sucesso!' % self.cloud_interval

也就是说,Python 3.5不再受到官方支持;强烈建议升级到3.6或更高版本。看见https://endoflife.date/python了解更多信息。

最新更新