我知道F Strings是在^{中引入的。为此我得到了错误-Invalid SyntaxDATA_FILENAME = 'data.json'
def load_data(apps, schema_editor):
Shop = apps.get_model('shops', 'Shop')
jsonfile = Path(__file__).parents[2] / DATA_FILENAME
with open(str(jsonfile)) as datafile:
objects = json.load(datafile)
for obj in objects['elements']:
try:
objType = obj['type']
if objType == 'node':
tags = obj['tags']
name = tags.get('name','no-name')
longitude = obj.get('lon', 0)
latitude = obj.get('lat', 0)
location = fromstr(F'POINT({longitude} {latitude})', srid=4326)
Shop(name=name, location = location).save()
except KeyError:
pass
错误-
^{pr2}$
所以我用了-fromstr('POINT({} {})'.format(longitude, latitude), srid=4326)
这个错误被删除了,对我有效。然后我找到了这个库future-fstrings。我应该用它吗。这将删除上面的Invalid Error