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

时间:2012-06-27 03:20:07

标签: python django google-app-engine

在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所以我迷失在这里。感谢

1 个答案:

答案 0 :(得分:2)

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