Wednesday, September 4, 2013

Re: Do I always have to run collectstatic to serve uploaded images by apache?

The MEDIA_ROOT is the local system location where the FileField in your models is going to store incoming files. Users submit files and they are placed in the location specified by the 'upload_to' setting of the field (usually a directory within MEDIA_ROOT).

https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to

You should remove your MEDIA_ROOT from STATICFILES_DIRS.

Then you should review this documentation.

https://docs.djangoproject.com/en/dev/topics/http/file-uploads/

The 'collectstatic' command collects your static assets, not user submitted content. Your system is misconfigured and that is why it is collecting user submitted files.

K


On Wednesday, September 4, 2013 12:41:03 PM UTC-7, Robin Lery wrote:

I have a site, where users can upload images. And it works fine in django's own server. But I am using apache to serve both my app and statics. And when I upload any image, I can't see the pics. Only when I runcollectstatic I can see them. Do I always have to run collectstatic? Is there any better way to do this?

my settings.py snippet:

MEDIA_ROOT = 'C:/Users/Robin/web/leo/static'    STATIC_ROOT = 'C:/Users/Robin/static/'    STATICFILES_DIRS = (      "C:/Users/Robin/web/leo/static",

apache http.cont snippet:

AliasMatch ^/([^/]*\.css) C:/Users/Robin/static/styles/$1    Alias /static/ C:/Users/Robin/static/    <Directory C:/Users/Robin/static>  Order deny,allow  Allow from all  </Directory>    WSGIScriptAlias / C:/Users/Robin/web/leo/leo/wsgi.py    <Directory C:/Users/Robin/web/leo/leo>  <Files wsgi.py>  Order allow,deny  Allow from all  </Files>  </Directory>

Please guide me. Any help will be appreciated greatly. Thank you!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment