Images not showing. I get a 404 not found

5,456 views
Skip to first unread message

Michael Lind Hjulskov

unread,
Aug 30, 2013, 4:53:55 AM8/30/13
to django...@googlegroups.com
Hi

Im a newstarter and Im having trouble viewing the uploaded img files.
Both category and product images.
Files are uploaded but cannot be viewed - i get 404 not found
All the oscar icons is shown correctly after I configured urls.py for staticfiles (whatever that means :) and ran the command ./manage.py collectstatic

Here is my urls.py
from django.conf.urls import patterns, include, url
from oscar.app import application
from django.contrib import admin
admin.autodiscover()
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = patterns('',
    ('^admin/', include(admin.site.urls)),
    (r'', include(application.urls))
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

---------------------

Here is some of the img settings I made in settings.py
MEDIA_ROOT = location("public/media")
MEDIA_URL = '/media/'
STATIC_ROOT = BASE_PATH+'/static/'
STATIC_URL = '/static/'


----------------

I found a file named django.conf where this is in: (sorry I dont understand what this does, but maybe it  makes the mess)
$HTTP["host"] =~ "(^|\.)myproject\.dk$" {
    fastcgi.server = (
        "/django.fcgi" => (
            "main" => (
                "socket" => env.HOME + "/myproject/myproject.sock",
                "check-local" => "disable",
            )
        ),
    )
    alias.url = (
        "/media" => env.HOME + "/myproject/myproject/media",
        "/static" => env.HOME + "/myproject/myproject/static",
    )

    url.rewrite-once = (
        "^(/media.*)$" => "$1",
        "^(/static.*)$" => "$1",
        "^/favicon\.ico$" => "/media/favicon.ico",
        "^(/.*)$" => "/django.fcgi$1",
    )
}

---------------

example imagefile is in
/myproject/myproject/public/media/images/products/2013/08/20130827_175444.jpg
and when I click to view this img the link is pointing to
http://www.myproject.com/media/images/products/2013/08/20130827_175444.jpg


Thanks :o)

Michael

Izidor Matušov

unread,
Aug 30, 2013, 6:44:04 AM8/30/13
to django...@googlegroups.com
Your configuration file:

On 30/08/13 09:53, Michael Lind Hjulskov wrote:
> "/media" => env.HOME + "/myproject/myproject/media",

Actual filepath:
> /myproject/myproject/public/media/images/products/2013/08/20130827_175444.jpg

You're missing /public/ before media folder, so the configuration might
look like this:

> "/media" => env.HOME + "/myproject/myproject/public/media",


Izidor Matušov
Developer

Tangent Snowball
84-86 Great Portland Street
London
W1W 7NR




www.tangentsnowball.com

Tangent Snowball is a registered trading name of Tangent Marketing Services Limited
Registered Office: 84-86 Great Portland Street, London W1W 7NR
Registered in England Wales Number 4323657

This message contains confidential information and is intended only for the individual named.
If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by e-mail if you have received this e-mail by mistake
and delete this e-mail from your system.


Michael Lind Hjulskov

unread,
Aug 30, 2013, 8:19:20 AM8/30/13
to django...@googlegroups.com, izidor....@tangentsnowball.com
Hi Izidor

Thank You

I just tried that exact approach, and restarted the env
I updated the browser using ctrl+F5 and tried the link
Still not showing :(

Shown link is unchanged and response is the same


Den fredag den 30. august 2013 12.44.04 UTC+2 skrev Izidor Matušov:
Your configuration file:

On 30/08/13 09:53, Michael Lind Hjulskov wrote:
> "/media" => env.HOME + "/myproject/myproject/media",

Actual filepath:
> /myproject/myproject/public/media/images/products/2013/08/20130827_175444.jpg

You're missing /public/ before media folder, so the configuration might
look like this:

 > "/media" => env.HOME + "/myproject/myproject/public/media",


Izidor Matušov
Developer

Tangent Snowball
84-86 Great Portland Street
London
W1W 7NR

Izidor Matušov

unread,
Aug 30, 2013, 8:45:46 AM8/30/13
to django...@googlegroups.com
Can you access the media file itself? (might need some tinkering to
guess correct address) Firstly, an image has to be served by your server.

On 30/08/13 13:19, Michael Lind Hjulskov wrote:
> Hi Izidor
>
> Thank You
>
> I just tried that exact approach, and restarted the env
> I updated the browser using ctrl+F5 and tried the link
> Still not showing :(
>
> Shown link is unchanged and response is the same


Izidor Matušov
Developer

Tangent Snowball
84-86 Great Portland Street
London
W1W 7NR




www.tangentsnowball.com

Tangent Snowball is a registered trading name of Tangent Marketing Services Limited
Registered Office: 84-86 Great Portland Street, London W1W 7NR
Registered in England Wales Number 4323657

This message contains confidential information and is intended only for the individual named.
If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by e-mail if you have received this e-mail by mistake

Michael Lind Hjulskov

unread,
Aug 30, 2013, 9:00:43 AM8/30/13
to django...@googlegroups.com, izidor....@tangentsnowball.com
I have tried this
moved file test.jpg to /myproject/myproject/media/test.jpg
and i can acces it now via http://www.myproject.com/media/test.jpg
What does that indicate?


Den fredag den 30. august 2013 14.45.46 UTC+2 skrev Izidor Matušov:
Can you access the media file itself? (might need some tinkering to

Michael Lind Hjulskov

unread,
Aug 30, 2013, 12:18:29 PM8/30/13
to django...@googlegroups.com, izidor....@tangentsnowball.com
I dont know if this can help

I tried moving all files from /myproject/myproject/public/media/ to /myproject/myproject/media/ and it showed pictures correctly
But the I tried uploading a new picture, and it recreated the public library and generated sub dirs and put the newfiles there.
So I guess whats wrong is only the urls configuration
But how the heck do I fix this :o)

Michael Lind Hjulskov

unread,
Aug 30, 2013, 12:55:31 PM8/30/13
to django...@googlegroups.com, izidor....@tangentsnowball.com
I changed
MEDIA_ROOT = location("public/media")
to
MEDIA_ROOT = location("media")

restarted

and now product images shows correctly and I can upload new files - huraaaay

I still havent got a clue what was wrong and how I could correct it.

I really want to understand this :o)

Maik Hoepfel

unread,
Sep 6, 2013, 11:44:41 AM9/6/13
to django...@googlegroups.com, izidor....@tangentsnowball.com
Hi Michael,

the MEDIA_ROOT/etc. stuff is purely related to Django, Oscar doesn't do any magic. So I recommend the Django docs for understanding what's going on.

Hope that helps,

Maik

MONICA PHALSWAL

unread,
Oct 10, 2013, 5:08:50 AM10/10/13
to django...@googlegroups.com, izidor....@tangentsnowball.com

Hi,
I am having a similar problem. Could you please post yoru complete media specific settings.
Thanks in advance.

Maik Hoepfel

unread,
Oct 11, 2013, 6:30:59 AM10/11/13
to django...@googlegroups.com
Monica,

both the sandbox site and demo site in the Oscar repo have working settings:

https://github.com/tangentlabs/django-oscar/blob/master/sites/demo/settings.py
https://github.com/tangentlabs/django-oscar/blob/master/sites/sandbox/settings.py

Regards,

Maik
> --
> https://github.com/tangentlabs/django-oscar
> http://django-oscar.readthedocs.org/en/latest/
> https://twitter.com/django_oscar
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "django-oscar" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-oscar/CiujM572GuU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-oscar...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-oscar.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-oscar/e2a81358-088f-4f4e-87d8-dff7ce84769c%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Message has been deleted

Yağız Nalçakan

unread,
Aug 29, 2016, 10:02:07 AM8/29/16
to django-oscar, maik.h...@tangentsnowball.com
Hello,

First of all, I am trying to add images to a product. But I am giving ProductImage models' original field a http url. But it didn't upload with ImageField upload_to method.
it give an error like that:

Is there a way to add images from an http url?

And second of all, When I want to add an image from dashboard, it didn't seen after saving.

Can you help me about that issue?

Regards,
Yağız


11 Ekim 2013 Cuma 13:30:59 UTC+3 tarihinde Maik Hoepfel yazdı:

John

unread,
Aug 30, 2016, 1:56:34 PM8/30/16
to django-oscar, maik.h...@tangentsnowball.com
For your second issue, add these lines in your root project's urls.py, at the end. 

if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT,}),
)

harish kumar

unread,
Oct 21, 2016, 5:19:13 AM10/21/16
to django-oscar
thanku

PaKaNoSuKi KeNuiCha

unread,
Jan 30, 2017, 4:59:42 AM1/30/17
to django-oscar, maik.h...@tangentsnowball.com
Put this in urls.py 

from django.conf import settings
from django.conf.urls.static import static

urlpatterns =[

... # your urls setting.

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)




เมื่อ วันจันทร์ที่ 29 สิงหาคม ค.ศ. 2016 21 นาฬิกา 02 นาที 07 วินาที UTC+7, Yağız Nalçakan เขียนว่า:
Reply all
Reply to author
Forward
0 new messages