I am trying to understand how to create a link to static files in jinja2.
Everything I look up relates to Flask whereas I am using just webapp2 at this stage.
My main.py file looks as follows:
import os
import urllibfrom google.appengine.api import users
from google.appengine.ext import ndbimport jinja2
import webapp2JINJA_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)
My base.html template contains the links to the static files in "/css", "/js" "/images" etc.
When I look at the localhost:8080/ and localhost:8080/consults all the static files are working. Page looks fine.
However the next level in the structure localhost:8080/consults/create-consult is not linking to static files.
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.
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.
I tried to replace my css link with
href="{{ uri_for('static', filename='css/screen.css') }}"
I was told by App Engine uri_for not set.
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.
Any help appreciated.