0

I am following a tutorial on youtube for deploying a django app on DigitalOcean.

I type in: python3 manage.py collectstatic

This is the error message I get:

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'

I know the code is right cause I got in straight from GitHub. I am a complete beginner at this. I know that indentation could be the issue here but everything looks fine to me.

Here is the code for the manage.py file:

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)
5
  • do you install Pillow? Commented Jan 8, 2019 at 3:10
  • In your Onetoonefield use related_name='user'. Then try to collectstatic Commented Jan 8, 2019 at 3:16
  • change it to self.user.username, (you may get error warning) it will work correctly, Commented Jan 8, 2019 at 5:11
  • @BidhanMajhi Try to prevent all warnings if you can. Warnings exist for a reason: They may lead up to unexpected behaviour in the future. Commented Jan 8, 2019 at 10:09
  • All I was referring about IDE error due to dynamic language. I said that just because username is in User model not in Profile model so it can show no 'username' member. Not referring to any programming error, though. @JerkMan Commented Jan 8, 2019 at 10:23

1 Answer 1

2

You are trying to use f-string in Python 3.5 but they appeared in Python 3.6.

Change f'{self.user.username} Profile' to be '{} Profile'.format(self.user.username) or change your Python to be 3.6.

Sign up to request clarification or add additional context in comments.

3 Comments

Amazing. Thank you so much. This was my first post. I almost gave up but good thing this site and people like you exist to help. As someone who is trying to change their life and get out of a dead end job, I would like to thank you!
I'm glad it helped. Please make vote up and mark my answer as solution if it helped according to stackoverflow.com/help/someone-answers
Ok. Done! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.