title: Rendering Static file in Wkhtmltopdf in Django
body: <p>I have followed too many answers to this but I need some more explanation on this topic as I want to know the root cause for it.</p>
  
  <p>I am trying to create pdf using wkhtmltopdf.</p>
  
  <p>This is my setting files look like :</p>
  
  <p><code>Settings.py</code></p>
  
  <pre><code>    STATIC_URL = '/static/'
  
  STATICFILES_DIRS = (
      os.path.join(BASE_DIR, 'static'),
  )
  
  STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  </code></pre>
  
  <p>And the URL to reference static file is :</p>
  
  <pre><code>&lt;link rel="stylesheet" href="{% static '/css/template_pdf.css' %}" type="text/css" /&gt;
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>&lt;link rel="stylesheet" href="/static/css/template_pdf.css" type="text/css" /&gt;
  </code></pre>
  
  <p>or </p>
  
  <pre><code>&lt;link rel="stylesheet" href="file:///static/css/template_pdf.css" type="text/css" /&gt;
  </code></pre>
  
  <p>or</p>
  
  <p>I used this too:
  <a href="https://gist.github.com/renyi/f02b4322590e9288ac679545df4748d3" rel="nofollow noreferrer">https://gist.github.com/renyi/f02b4322590e9288ac679545df4748d3</a></p>
  
  <p>and provided url as :</p>
  
  <pre><code>&lt;link rel='stylesheet' type='text/css' href='{{ STATIC_URL }}static/css/template_pdf.css' /&gt;
  </code></pre>
  
  <p>But the issue I understood is, all of the above except last one works perfectly while rendering view :</p>
  
  <pre><code>def view_pdf(request):
      """View function for home page of site."""
  
      context= {'title': 'Hello World!'}
  
      # Render the HTML template index.html with the data in the context variable
      return render(request, 'pdf/quotation.html', context=context)
  </code></pre>
  
  <p>But for creating pdf using wkhtmltopdf it specifically needs the url to be specified like :</p>
  
  <pre><code>&lt;link rel="stylesheet" href="http:localhost:8000/static/css/template_pdf.css" type="text/css" /&gt;
  </code></pre>
  
  <p>I know I am missing something in the static file. But I want to know why it works with rendering template but not with Generating pdf using wkhtmltopdf.
  I dont think it is good idea to put directly domain name inside the referencing url.</p>
  
  <p>A detailed solution for this would be helpful as I am very new to django.</p>
  
  <p>I tried follow this answer too but nothing worked : <a href="https://stackoverflow.com/questions/19445486/django-wkhtmltopdf-dont-reading-static-files">Django wkhtmltopdf don&#39;t reading static files</a></p>