SyntaxError:COLLECTSTATIC(PYTHON)的语法无效

时间:2019-01-08 03:02:39

标签: python django deployment

我正在按照youtube上的教程在DigitalOcean上部署django应用。

我输入:python3 manage.py collectstatic

这是我收到的错误消息:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/home/mochimoko/django_project/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/mochimoko/django_project/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/home/mochimoko/django_project/venv/lib/python3.5/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/mochimoko/django_project/venv/lib/python3.5/site-packages/django/apps/registry.py", line 112, in populate
    app_config.import_models()
  File "/home/mochimoko/django_project/venv/lib/python3.5/site-packages/django/apps/config.py", line 198, 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 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 661, in exec_module
  File "<frozen importlib._bootstrap_external>", line 767, in get_code
  File "<frozen importlib._bootstrap_external>", line 727, in source_to_code
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/mochimoko/django_project/users/models.py", line 11
    return f'{self.user.username} Profile'

我知道代码是正确的,因为我直接从GitHub获得。 我是一个完整的初学者。我知道缩进可能是这里的问题,但对我来说一切都很好。

这是manage.py文件的代码:

from django.db import models
from django.contrib.auth.models import User
from PIL import Image


class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    image = models.ImageField(default='default.jpg', upload_to='profile_pics')

    def __str__(self):
        return f'{self.user.username} Profile'

    def save(self, *args, **kawrgs):
        super().save(*args, **kawrgs)

        img = Image.open(self.image.path)

        if img.height > 300 or img.width > 300:
            output_size = (300, 300)
            img.thumbnail(output_size)
            img.save(self.image.path)

1 个答案:

答案 0 :(得分:2)

您正试图在Python 3.5中使用f-string,但它们出现在Python 3.6中。

f'{self.user.username} Profile'更改为'{} Profile'.format(self.user.username)或将Python更改为3.6。