0

I am trying to open media file in django. when i run the project on local system. It runs if file does not exists then image error icon come. But when i deploy that on the server if file does not exists it is giving the error. Path of the file is save in database and file is not present in the folder.

No such file or directory: u'/home/ec2-user/dev/indianangelnetwork.web.backend/indianangelnetwork/media/job_portfolio_logo/2015-01-29 06:58:59_WebEngage-logo-with-WK.jpg

Please help some body. Thanks

aman kumar
  • 3,086
  • 1
  • 17
  • 24

1 Answers1

0

Add this condition before load file

{% if path_to_file %}
    <img src="{{ path_to_file }}" >
{% else %}
{% endif %}

Here is example of loading avatar from some user model:

{% for item in user %}
    {% if not item.avatar %}
        <p> no avatar here </p>
    {% else %}
        <img src="{{ item.avatar.url }}" >
    {% endif %}
{% endfor %}
Ivan Semochkin
  • 8,649
  • 3
  • 43
  • 75
  • path of the is save in database. And file is not present – aman kumar Jan 07 '16 at 12:19
  • I have the save url in database but that file is not present in the folder. for EX- url is /home/ec2user/dev/indianangelnetwork.web.backend/indianangelnetwork/media/job_portfolio_logo/2015-01-29 06:58:59_WebEngage-logo-with-WK.jpg but file does not exits at the location. That why it is displaying the error. – aman kumar Jan 07 '16 at 12:22
  • check my answer here http://stackoverflow.com/questions/34563454/django-imagefield-upload-to-path/34563512#34563512 Maybe you have bad settings – Ivan Semochkin Jan 07 '16 at 12:23
  • so what your problem? it is unclear. If you try loading file whitch does exist it is load or not? If it not, check my settings in answer. If it exception run only when file does not exist, so template tags in my answer should work. Try to explain your problem more clearly – Ivan Semochkin Jan 07 '16 at 12:38
  • i am not trying to load. Suppose i have path of image in database img/as.png but image is not in actual folder. When i appy it gives url img/as.png. but this image does not exists in folder. It is raising the error no such file. – aman kumar Jan 07 '16 at 12:42
  • So if your setting well, `media_url` using for upload files. If you strored this files for dev things, like using for title image. You need to put this files in `static` folder. Make sure you have settings like `STATIC_URL = '/static/'` and `STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)` then create directory in `static` named like `dev_images` and then load in template like this ` – Ivan Semochkin Jan 07 '16 at 13:03