Ich habe ein Modell, das user_image Feld enthält. Dieses Feld hat Standard-Bildwert:Django 1.10 zeigt kein statiques Bild
user_image = models.ImageField(verbose_name='Аватар',blank=True, default=settings.STATIC_URL+'avatar.jpeg')
nach dem Update 1.10 das Standardbild django zeigt nicht in Vorlagen, da Link falschen Pfad enthält. Zum Beispiel in meinem Fall Link
'127.0.0.0:8000/static/avatar.jpeg'
stattdessen sollte ich Link wie diesen
'127.0.0.0:8000/media/static/avatar.jpeg'
Python Konsole Ausgänge
>>>u.userprofiletable_set.get().user_image
<ImageFieldFile: /static/avatar.jpeg>
>>> u.userprofiletable_set.get().user_image.url
'/media/static/avatar.jpeg'
>>> u.userprofiletable_set.get().user_image.path
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/korablevop/.virtualenvs/mynewenv/lib/python3.5/site-packages/django/db/models/fields/files.py", line 64, in _get_path
return self.storage.path(self.name)
File "/Users/korablevop/.virtualenvs/mynewenv/lib/python3.5/site-packages/django/core/files/storage.py", line 407, in path
return safe_join(self.location, name)
File "/Users/korablevop/.virtualenvs/mynewenv/lib/python3.5/site-packages/django/utils/_os.py", line 78, in safe_join
'component ({})'.format(final_path, base_path))
django.core.exceptions.SuspiciousFileOperation: The joined path (/static/avatar.jpeg) is located outside of the base path component (/Users/korablevop/PycharmProjects/sxodu/media)
, zeigen Sie Ihre Datei settings.py –
'STATIC_URL = '/ static /' STATICFILES_DIRS = ( os.path.join (BASE_DIR, 'statisch'), 'statisch', ) MEDIA_ROOT = os .path.join (BASE_DIR, 'media /') MEDIA_URL = '/ media /' ' – Oleg
Ich habe versucht, deine Situation nachzuahmen, aber in meinem Fall funktioniert alles gut. Ich finde diesen Post mit ähnlichem Problem wie Sie http://stackoverflow.com/questions/33625173/suspici-file-operation-the-joined-path-is-located-outside-of-the-base-pa, hoffe es hilft Sie. –