Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango in Google App Engine - Python 2.7
    primarykey
    data
    text
    <p>I am in the process of migrating some GAE apps from Python 2.5 to 2.7. It seems much more difficult to import Django templates (any version) into this version of Python. I followed Google's instructions to the T and scoured the web for help, but ultimately failed. So here is what I tried, and I was wondering if any of you guys would be able to help me! Thanks in advance.</p> <p>In app.yaml:</p> <pre><code>libraries: - name: django version: "1.2" </code></pre> <p>In main.yaml:</p> <pre><code>import os # specify the name of your settings module os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings' import django.core.handlers.wsgi app = django.core.handlers.wsgi.WSGIHandler() </code></pre> <p>The main class:</p> <pre><code>class Main(webapp2.RequestHandler): def get(self): self.response.out.write(template.render('index.html', None)) </code></pre> <p>The Error I get:</p> <blockquote> <p>NameError: global name 'template' is not defined</p> </blockquote> <p>Interestingly, it worked with Jinja2 templates. However, all HTML code was written using Django templates and I think it would be too time consuming to convert them all. Here's the Jinja2 code that worked (all in one code block for simplicity).</p> <pre><code>libraries: - name: jinja2 version: latest import jinja2 import os jinja_environment = jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.dirname(__file__))) class Main(webapp2.RequestHandler): def get(self): template = jinja_environment.get_template('index.html') self.response.out.write(template.render()) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload