I put the image("hi.png") and css file in /home/user1/djangoblog/blog/static
In templates i have <img src="{{ STATIC_URL }}images/hi.png" />
I edited the settings.py =>
STATIC_ROOT = ''
STATIC_URL = "/static/"
STATICFILES_DIRS = (
"/home/user1/djangoblog/blog/static/",)
The web page source returns =>
<div><img src="/static/images/a.jpg" /></div>
If the views.py => The image is not displayed on the web page.
now = datetime.datetime.now()
#return render_to_response('current_datetime.html', {"foo": now}, context_instance=RequestContext(request))
t = loader.get_template('current_datetime.html')
c = Context({'foo': now})
return HttpResponse(t.render(c))
But if the views.py => it displays the images on the web page.
return render_to_response('current_datetime.html', {"foo": now}, context_instance=RequestContext(request))
It looks like it's a problem with HttpResponse or RequestContext. How can i fix this problem with HttpResponse or RequestContext?
RequestContextinstead ofContextotherwise you don't get any of the variables created byTEMPLATE_CONTEXT_PROCESSORS.TEMPLATE_COnTEXT_PROCESSORSRequestContextinstead ofContext. UseContextonly when you don't need those variables. Okay? Seems like you are digging yourself deeper and deeper into misunderstanding. There's no reason to change your STATIC_URL, there's no reason to useContextinstead ofRequestContextand actually you really should just userender_to_templateor even justrenderunless you have a compelling reason otherwise.