Unable to serve static files like css, js in django python

前端 未结 4 2355
轻奢々
轻奢々 2020-12-06 17:41

I am very new to django, and gone through tutorial for many days , i have started building a small website using django and trying to serve a css f

4条回答
  •  鱼传尺愫
    2020-12-06 18:14

    Your problem is related to this line:

    return render_to_response("home_page.html")
    

    Django's template engine requires two things to properly render a template.

    1. The template name
    2. A context variable

    The context variable is a key/value dictionary listing all of the variables available to the template.

    The render_to_response shortcut actually accepts two different context variable parameters.

    You're missing both.

    Without these variables, the template doesn't have ANY variables available to it. So your {{ STATIC_URL }} template variable is probably blank.

    To correct, try this:

    from django.shortcuts import render_to_response
    from django.template import RequestContext
    
    def home_page(request):
        return render_to_response("home_page.html", {}, context_instance=RequestContext(request))
    

提交回复
热议问题