Opened 5 years ago

Closed 5 years ago

Last modified 14 months ago

#13943 closed Uncategorized (invalid)

the upload_to attribute does not append MEDIA_URL automaticaly

Reported by: dantario@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords: FileField, upload_to, ImageField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

the upload_to attribute on FileField didn't append MEDIA_URL setting automatically when submit a form from django admin

this is my field syntax from my model:
thumb = models.ImageField(upload_to='news')

Change History (2)

comment:1 Changed 5 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

upload_to is used as described here: http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to

That does not include appending MEDIA_URL to the name. Rather, MEDIA_ROOT is prepended to the upload_to value. This does work. If you are having trouble in this area the django-users mailing list or #django IRC channel would be a better place to ask for guidance, since really the basics of uploading files are really not broken in 1.2. When describing your problem it would be best to include all relevant settings (MEDIA_ROOT and MEDIA_URL) and more description of what exactly the problem you are observing is.

comment:2 Changed 14 months ago by GDorn

  • Easy pickings unset
  • Severity set to Normal
  • Type set to Uncategorized
  • UI/UX unset

This is no longer true as of Django 1.6. upload_to does not prepend MEDIA_ROOT, but you are responsible for ensuring that upload_to starts with MEDIA_ROOT.

If it doesn't, you will get a 400 Bad Request response to POST, which is exceptionally hard to debug if you don't have some form of logging enabled.

Note: See TracTickets for help on using tickets.
Back to Top