2012-06-27 45 views
0

我一直在谷歌App Engine的使用時,Django模板收到此錯誤:谷歌App Engine的Python的Django的TemplateSyntaxError:無效的塊標籤: 'ENDIF'

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,所以我迷失在這裏。由於

+0

好像有在「%」和「}」之間的空間你關閉模板中的{%if ...'標記。它應該是'%}'而不是'%}'。 –

回答

2

有在這一行「%」和「}」之間的額外空間
{% if action1 == "manage_companies" % } 嘗試將其更改爲
{% if action1 == "manage_companies" %}

+0

這確實解決了這個錯誤,但提出了另一個,我不得不使用語法{%ifequal%}和{%endifequal%}。我需要使用不同於默認的django庫嗎? –