1

Im developing a code that performs multiple functions in the template and i have used scripts to check the functions using if else and for loops, but i am getting these kinds of errors, please help me know the reasons, thank you in advance

if you see at the end of the code inside the script tag the declaration of if else tag must be somewhat like the code below, but as soon as i save the code it gets unformatted and gives me errors

this is the code snippet image

And the errors

 {% if messages %}
        {% for message in messages %}
            alert('{{message}}')
        {% endfor %}
    {% endif %}

Upload.html file

{% extends 'base.html' %} {% block content %}

<div class="form-group">
    <label for="name" class="col-md-3 col-sm-3 col-xs-12 control-label">Select : </label>
    <div class="col-md-8">

        <select name="cars" id="cars">
 <option value="">Select</option>
  <option value="WithTime">AmpandFreq</option>
  <option value="WithoutTime">Amplitude</option>
  
</select>
    </div>
</div>


<div id="withtime" style="display:none">
    <form action="/csvapp/upload/" method="POST" enctype="multipart/form-data" class="form-horizontal">
        {% csrf_token %}
        <div class="form-group">
            <label for="name" class="col-md-3 col-sm-3 col-xs-12 control-label">File: </label>
            <div class="col-md-8">
                <input type="file" name="csv_file" id="csv_file" required="True" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-3 col-sm-3 col-xs-12 col-md-offset-3" style="margin-bottom:10px;">
                <button class="btn btn-primary"> <span class="glyphicon glyphicon-upload" style="margin-right:5px;"></span>Upload </button>
            </div>
        </div>
    </form>
</div>

<div id="withouttime" style="display:none">
    <form name="form" action="/csvapp/upload_withouttime/" method="POST" enctype="multipart/form-data" class="form-horizontal">
        {% csrf_token %}
        <div class="form-group">
            <label for="name" class="col-md-3 col-sm-3 col-xs-12 control-label">File: </label>
            <div class="col-md-8">
                <input type="file" name="csv_file" id="csv_file" required="True" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label for="name" class="col-md-3 col-sm-3 col-xs-12 control-label">Sampling Frequency: </label>
            <div class="col-md-8">
                <input type="text" name="sampfreq" id="sampfreq" required="True" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-3 col-sm-3 col-xs-12 col-md-offset-3" style="margin-bottom:10px;">
                <button class="btn btn-primary"> <span class="glyphicon glyphicon-upload" style="margin-right:5px;"></span>Upload </button>
            </div>
        </div>
    </form>
</div>


<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
    { %
        if messages %
    } { %
        for message in messages %
    }
    alert('{{message}}') { % endfor %
    } { % endif %
    }
    $('select').on('change', function() {

        var a = $(this).val()


        { %
            if a == "WithoutTime" %
        } {
            alert("inside")
            $('#withtime').hide();
            $('#withouttime').show();
        } { %
            else %
        } {
            $('#withtime').hide();
            $('#withouttime').show();
        }
    })
</script>
{% endblock %}
4
  • 1
    why do you have space in between { % ? Commented Apr 19, 2021 at 12:32
  • Remove the space between the { and %. Also can we check what IDE you are using as well if you still have issues after that. Currently your IDE in recognising the code as Javascript due to the space. This should be fixed be removing the space but if it isn't then knowing the IDE will help with the next steps Commented Apr 19, 2021 at 13:06
  • @SteveMapes I'm using Visual Studio Code and I have removed the space in between { and % however as soon as I save my code it automatically gives spacing and throws me a error. Commented Apr 20, 2021 at 3:33
  • 1
    Okay. I've not really used VSC but I assume you've pointed it at your python interpreter? code.visualstudio.com/docs/python/tutorial-django I'm not sure if this is still needed but there's also a plugin for Django Template support. I'm surprised it would need it since it has Python support but that may be worth looking at marketplace.visualstudio.com/…. Could this also be useful? automationpanda.com/2018/02/08/… Commented Apr 20, 2021 at 9:29

1 Answer 1

2

After Searching and varying many internal settings I came to a simple conclusion for the errors and the requirement

In the command palette (ctrl-shift-p) select Install Extension and choose Django Template.

To get started on the extension...

  1. Go to the Debug viewlet and select Launch Extension then hit run (F5). This will launch a second instance of Code with the extension from the first window loaded.

  2. As you make changes, you can also reload (Ctrl+R or Cmd+R on Mac) the second Code window to load any changes.

for more information refer the link below Django Template view[https://marketplace.visualstudio.com/items?itemName=bibhasdn.django-html]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.