Django STATIC_URL is not working

后端 未结 5 815
渐次进展
渐次进展 2020-12-15 22:53

Django version is 1.4. I had read the official document, and googled my problem.

first I had followed the official document Managing static files added

5条回答
  •  渐次进展
    2020-12-15 23:39

    Unfortunately, Django's render_to_response shortcut by default uses normal template context, which does not include context processors and all their fancy and useful stuff like STATIC_URL. You need to use RequestContext, which does precicely that.

    This can be called by using the new render (available since Django 1.3):

    from django.shortcuts import render
    
    return render(request, 'register.html', {'errors':errors})
    

    In Django 1.2 and older, you need to supply the context explicitly:

    from django.shortcuts import render_to_response
    from django.template import RequestContext
    
    return render_to_response('register.html', {'errors':errors},
        context_instance=RequestContext(request))
    

提交回复
热议问题