Skip to main content
deleted 23 characters in body; edited title
Source Link
dda
  • 6.2k
  • 2
  • 27
  • 35

django Django in google app engineGoogle App Engine - pythonPython 2.7

I am in the process of migrating some GAE apps from pythonPython 2.5 to 2.7. It seems much more difficult to import djangoDjango templates (any version) into this version of pythonPython. I followed Google's instructions to the teeT 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.

In app.yaml:

libraries:
- name: django
  version: "1.2"

In main.yaml:

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()

The main class:

class Main(webapp2.RequestHandler):
  def get(self):
    self.response.out.write(template.render('index.html', None))

The Error I get:

NameError: global name 'template' is not defined

NameError: global name 'template' is not defined

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).

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())

django in google app engine - python 2.7

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 tee 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.

In app.yaml:

libraries:
- name: django
  version: "1.2"

In main.yaml:

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()

The main class:

class Main(webapp2.RequestHandler):
  def get(self):
    self.response.out.write(template.render('index.html', None))

The Error I get:

NameError: global name 'template' is not defined

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).

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())

Django in Google App Engine - Python 2.7

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.

In app.yaml:

libraries:
- name: django
  version: "1.2"

In main.yaml:

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()

The main class:

class Main(webapp2.RequestHandler):
  def get(self):
    self.response.out.write(template.render('index.html', None))

The Error I get:

NameError: global name 'template' is not defined

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).

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())
Source Link
mrmo123
  • 725
  • 1
  • 8
  • 24

django in google app engine - python 2.7

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 tee 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.

In app.yaml:

libraries:
- name: django
  version: "1.2"

In main.yaml:

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()

The main class:

class Main(webapp2.RequestHandler):
  def get(self):
    self.response.out.write(template.render('index.html', None))

The Error I get:

NameError: global name 'template' is not defined

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).

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())