Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

python - Django Template Syntax error: Could not pass the remainder

I am working on a Django project and I am relatively new to the Django framework. After running the application using python3 manage.py runserver I am getting an error like django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '['role']' from 'session['role']'. This is the particular html file to which the error is pointing. base.html

{% block body %}
  <body>
    <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
      <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#"><img src="{% static 'img/logo.png' %} "id="icon" alt="User Icon" width="30" > {{ application.name }}</a>
          {% if session['role'] == "manager" %}
# rest of code

How do I get this done with? please help

question from:https://stackoverflow.com/questions/65843481/django-template-syntax-error-could-not-pass-the-remainder

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can't do this in the Django template

try this

{% block body %}
  <body>
    <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
      <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#"><img src="{% static 'img/logo.png' %} "id="icon" alt="User Icon" width="30" > {{ application.name }}</a>
          {% if session.role == "manager" %}
# rest of code

Please refer this https://docs.djangoproject.com/en/3.1/ref/templates/language/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...