Re: images in a template
Thank You very much, Daniel !
I try to follow every advice of You and Mike.
> So you put the image in the media directory.
In a project directory 'galiontour' I created a subdirectory 'media'
and placed 'galion.gif' into it.
Index.html was placed into application level directory 'galion'.
> Then, you set up (for development only) the static serve view in your urls.py, as you have been shown.
That is what I don't understand yet.
Now I fill project level urls.py with this:
from galiontours.galion import views
from galion.views import index
from django.conf import settings
urlpatterns = patterns('',
url(r'^index/', 'galion.views.index'),
url(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_DOC_ROOT}),
)
The latter statement isn't clear for me yet. I omitted here some
statements in this file, serving for admin.
>Then you refer to the file in the template using MEDIA_URL, so your browser knows where to request the image.
In a template index.html I wrote:
#title h1 { background:{{ MEDIA_URL }}galion.gif left top no-
repeat; padding-left:80%; }
In addition, in settings.py I wrote:
MEDIA_URL = '/media/'
Now I put
http://localhost:8000/index/
to web browser and don't see an image in a homepage.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home