Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django not found static files in the subfolder of static

django 1.6.5

My static files is under subfolder of static.

djangoprj
    djangoprj
        settings.py
        urls.py
        wsgi.py
        __init__.py
    static
        myapp
            mystaticfiles
            ...
    apps
        myapp
            ...
            templates
                *.html
            ...

In my templates file, I link static file as full path.

<img src="/static/myapp/images/my.png" />

But those file are not found. I got 404 error.

When change settings.py as

STATIC='/static/myapp/'

I can get those static files. But I am not want to do that. Why dose it not wok, when STATIC='/static/'? Is there some easy way to solve this problem instead of doing command manaully, such as 'collectstatic'? I have put my static file in static folder, and I have used full path in my templates file. Why does it not work? Thanks in advance.

like image 607
Nick Dong Avatar asked Oct 22 '25 15:10

Nick Dong


1 Answers

Now that you switch the static file folder to '/static/myapp/'

You should use <img src="/static/images/my.png" /> in your tag.

Generally, you should use {% static %} template tag to do this, like below (assume STATIC='/static/').

{% load staticfiles %}

<img src="{% static 'myapp/images/my.png' %}" />

to learn more, see the tutorial, https://docs.djangoproject.com/en/1.6/intro/tutorial06/

I suggest you to read all the tutorial (part1 - part6) in https://docs.djangoproject.com/en/1.6/

So that you can know deep enough for the basis.

like image 62
Alfred Huang Avatar answered Oct 25 '25 06:10

Alfred Huang