title: jinja2 link to static files
body: <p>I am trying to understand how to create a link to static files in jinja2.</p>
  
  <p>Everything I look up relates to Flask whereas I am using just webapp2 at this stage.</p>
  
  <p>My main.py file looks as follows:</p>
  
  <pre><code>import os
  import urllib
  
  from google.appengine.api import users
  from google.appengine.ext import ndb
  
  import jinja2
  import webapp2
  
  JINJA_ENVIRONMENT = jinja2.Environment(
      loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
      extensions=['jinja2.ext.autoescape'],
      autoescape=True)
  
  class MainPage(webapp2.RequestHandler):
      def get(self): 
      template = JINJA_ENVIRONMENT.get_template('/templates/base.html')  
      self.response.out.write(template.render())
  
  class ConsultsPage(webapp2.RequestHandler):
      def get(self):
      template = JINJA_ENVIRONMENT.get_template('/templates/consults.html')  
      self.response.out.write(template.render())
  
  class CreateConsultPage(webapp2.RequestHandler):
      def get(self):
      template = JINJA_ENVIRONMENT.get_template('/templates/create-consult.html')  
      self.response.out.write(template.render())
  
  app = webapp2.WSGIApplication([
      ('/', MainPage),
      ('/consults', ConsultsPage),
      ('/schedule/create-consult', CreateConsultPage)
  ], debug=True)
  </code></pre>
  
  <p>My base.html template contains the links to the static files in "/css", "/js" "/images" etc.</p>
  
  <p>When I look at the localhost:8080/ and localhost:8080/consults all the static files are working. Page looks fine.</p>
  
  <p>However the next level in the structure localhost:8080/consults/create-consult is not linking to static files.</p>
  
  <p>When I view source I see that the css link has rendered as localhost:8080/consults/css/style.css , when the actual location is localhost:8080/css/style.css.</p>
  
  <p>I understand I may need to make all links dynamic via some environment variable called uri_for, but I can't find the correct way to implement this.</p>
  
  <p>I tried to replace my css link with </p>
  
  <pre><code>href="{{ uri_for('static', filename='css/screen.css') }}"
  </code></pre>
  
  <p>I was told by App Engine uri_for not set.</p>
  
  <p>Basically would like to know the correct process for setting uri_for and then how to incorporate it in the paths for my links to static files.</p>
  
  <p>Any help appreciated.</p>