Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango staticfiles with "With a template tag" method
    primarykey
    data
    text
    <p>I came from PHP, Python and Django are new to me. I have a simple problem but have already stuck with this for hours and still couldn't find out what went wrong. </p> <p>I want to insert a simple image into the template. </p> <p>I have followed <a href="https://stackoverflow.com/questions/7325196/templatesyntaxerror-staticfiles-is-not-a-valid-tag-library">TemplateSyntaxError &#39;staticfiles&#39; is not a valid tag library&#39;</a> and <a href="https://docs.djangoproject.com/en/1.3/howto/static-files/#with-a-template-tag" rel="nofollow noreferrer">https://docs.djangoproject.com/en/1.3/howto/static-files/#with-a-template-tag</a></p> <p>Following are my settings.</p> <ol> <li>my static folder is located in <code>/myproject/myapp/static/</code>. And the img path is <code>/static/images/hi.jpg</code>.</li> <li>the src value in img tag is <code>"/static/images/hi.jpg"</code> when the page is rendered</li> <li>Setting in setting.py</li> </ol> <pre> STATIC_URL = '/static/' INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', django.contrib.messages', 'django.contrib.staticfiles', 'myapp', 'django.contrib.admin') </pre> <ol start="4"> <li><p>In template, I have </p> <pre> {% load static %} {% get_static_prefix as STATIC_PREFIX %} </pre> <p>and the source part of the image</p> <p><pre></p> <p>src="{{ STATIC_PREFIX }}images/hi.jpg"</p></li> </ol> <p></pre></p> <ol start="5"> <li>finally, the url of the app is <a href="http://127.0.0.1:8000/myapp/" rel="nofollow noreferrer">http://127.0.0.1:8000/myapp/</a></li> </ol> <p>what part is wrongly configured? Any idea? Thank you so much for the help. Sorry for the poor formatting. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload