Vì vậy, tôi đã đập đầu vào tường. Tôi cảm thấy như tôi đã giải thích các tài liệu và ví dụ tôi tìm thấy, nhưng điều này dường như không biến mất.Vấn đề thẻ django mẫu tùy chỉnh trên AppEngine
Đây là mã thẻ:
from google.appengine.ext import webapp
register = webapp.template.create_template_register()
def test_tag():
return "TEST!"
register.simple_tag(test_tag)
Đây là mã chính:
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util, template
webapp.template.register_template_library('my_tags')
class MainHandler(webapp.RequestHandler):
def get(self):
self.response.out.write(template.render("test.html", {}))
def main():
application = webapp.WSGIApplication([('/', MainHandler)], debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
Dưới đây là các mẫu:
{% load my_tags %}
<html>{% test_tag %}></html>
Dưới đây là lỗi:
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django/django/template/defaulttags.py", line 750, in load
raise TemplateSyntaxError, "'%s' is not a valid tag library: %s" % (taglib, e)
TemplateSyntaxError: 'my_tags' is not a valid tag library: Could not load template library from django.templatetags.my_tags, No module named my_tags
Tôi thực sự ghét phải ra ngoài yêu cầu ai đó sửa mã của tôi, nhưng tôi dường như không thể hiểu tại sao điều này không hiệu quả. Bất kỳ gợi ý hay con trỏ nào sẽ được đánh giá cao.
jc