Google App Engine Python django TemplateSyntaxError:无效的块标签:'endif'

Posted

技术标签:

【中文标题】Google App Engine Python django TemplateSyntaxError:无效的块标签:\'endif\'【英文标题】:Google App Engine Python django TemplateSyntaxError: Invalid block tag: 'endif'Google App Engine Python django TemplateSyntaxError:无效的块标签:'endif' 【发布时间】:2012-06-28 10:56:01 【问题描述】:

在 Google App Engine 中使用 django 模板时,我不断收到此错误:

TemplateSyntaxError:无效的块标签:'endif'

python 代码:

class SuperAdmin(webapp.RequestHandler):
def get(self):

    #set the user object
    user = users.get_current_user()

    # See if user is logged in
    if user:  # signed in already
        #Create Logout URL
        logoutUrl = users.create_logout_url(self.request.uri)
        template_values['logoutUrl'] = logoutUrl

        #is this user a super admin
        isSuperAdmin = acl_authentication.AuthenticateUserViaAcl().isUserSuperAdmin(user.email(), user.user_id())
        template_values['isSuperAdmin'] = isSuperAdmin

        #Use our auth object to see if the user is allowed on this page
        if acl_authentication.AuthenticateUserViaAcl().IsUserPermitted(user.user_id(), user.email(), '0', '0', 50): #User is allowed
            self.response.out.write("This user is in the acl db and a super admin<br/>")

            #Add action1 to template_values
            template_values['action1'] = self.request.get('action1')

            #Write the Header
            path = os.path.join(os.path.dirname(__file__), 'adminHeader.html')
            self.response.out.write(template.render(path, template_values))

            #Write the Login Page
            path = os.path.join(os.path.dirname(__file__), 'SuperAdmin.html')
            self.response.out.write(template.render(path, template_values))

            #Write the Header
            path = os.path.join(os.path.dirname(__file__), 'adminFooter.html')
            self.response.out.write(template.render(path, template_values))

        else: #User is not allowed
            #Log to DB that we hit access denied page
            acl_authentication.AuthenticateUserViaAcl().LogToDbAccessDeniedHit(user.user_id(), user.email(), self.request.url)
            #Redirect to Access Denied Page
            self.redirect("/AccessDeniedPage")

    else: #User is not logged in
        self.redirect("/LoginPage?destUrl=" + self.request.url)  

.html模板代码

<!-- Begin If action1==manage_companies -->
                % if action1 == "manage_companies" % 
                    <tr>
                      <td>Manage Companies</td>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                % endif %
<!-- /End If action1==manage_companies -->

我不熟悉 django,所以我在这里迷路了。谢谢

【问题讨论】:

模板中% if ... 的结束标记中的“%”和“”之间似乎有一个空格。它应该是 '%' 而不是 '% '。 【参考方案1】:

在这一行的 '%' 和 '' 之间有一个额外的空格% if action1 == "manage_companies" % 尝试将其更改为% if action1 == "manage_companies" %

【讨论】:

这确实解决了这个错误,但又引发了另一个错误,我不得不使用语法 % ifequal % 和 % endifequal %。我需要使用与默认库不同的 django 库吗?

以上是关于Google App Engine Python django TemplateSyntaxError:无效的块标签:'endif'的主要内容,如果未能解决你的问题,请参考以下文章

python 将Google App Engine SDK添加到Python virtualenv

python Google App Engine:将CSV导入数据存储区

google-app-engine:google api python客户端hello world中的ImportError httplib2

Google App Engine 标准 Python 云构建

Google App Engine - 大查询 - Python 找不到库 google.cloud

Python 2.5 Google App Engine [关闭]