0
쿠키를 확인하고 값을 사용하여로드 할 템플릿을 설정해야합니다.클래스 메소드 (webapp2.RequestHandler)를 사용하여 쿠키를 확인하는 모듈 가져 오기 (GAE-Python)
import webapp2 as webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
import os
class genericPage(webapp.RequestHandler):
def get(self):
templatepath = os.path.dirname(__file__) + '/../templates/'
ChkCookie = self.request.cookies.get("cookie")
if ChkCookie == 'default':
html = template.render(templatepath + 'default_header.html', {})
else:
html = template.render(templatepath + 'alt_header.html', {})
self.response.out.write(html)
내 질문이 ChkCookie
를 이동하고 별도의 모듈로하면 ... else 문 위의 코드에서 호출하는 방법입니다 : 다음은 작업 코드입니다. 같은과 같은 :
# HOW I WANT TO MODIFY THE ABOVE CODE TO SET THE TEMPLATES WITH A COOKIE
import webapp2 as webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
import os
from testmodule import testlibrary
class genericPage(webapp.RequestHandler):
def get(self):
html = testlibrary.ChkCookieClass.ChkCookie()
self.response.out.write(html)
나는 genericPage
클래스의 ChkCookie
코드를 유지하고 모듈은이 같은 기능이 포함되어 때 성공적으로 라이브러리/모듈을 가져올 수 있습니다
# THIS IS THE MODULE I AM IMPORTING
import webapp2 as webapp
from google.appengine.ext.webapp import template
import os
def SkinChk(ChkCookie):
templatepath = os.path.dirname(__file__) + '/../templates/'
if ChkCookie == 'default':
out = template.render(templatepath + 'default_header.html', {})
else:
out = template.render(templatepath + 'alt_header.html', {})
return out
어떻게 것 I 위의 모듈 코드를 ChkCookie = self.request.cookies.get("cookie")
으로 수정하십시오.