Reputation: 2913
I have something very weird. I am on win7 Django 1.4. I have the following media_root/url settings :
MEDIA_ROOT = 'c:\project\uploads'
MEDIA_URL = '/media/'
My url.py includes :
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT}))
I have a model with the the field :
file = models.FileField(upload_to=MEDIA_ROOT, blank = True)
Now, I am uploading the file via the admin site, the file is uploaded successfully. however , the when accessing the file via the admin I see the link to the file is :
http://127.0.0.1:8000/media/c:\project\uploads\[filename]
I have no clue what I am doing wrong.
Upvotes: 0
Views: 2742
Reputation: 22449
I think your model is wrong:
file = models.FileField(upload_to=MEDIA_ROOT, blank = True)
upload_to expects a relative path which is added to the MEDIA_ROOT, so now it expects the file to be at MEDIA_ROOT/MEDIA_ROOT which makes no sense.
Try something like:
file = models.FileField(upload_to='files', blank = True)
docs:
FileField.upload_to A local filesystem path that will be appended to your MEDIA_ROOT setting to determine the value of the url attribute.
Upvotes: 2