简体   繁体   中英

In PyCharm: “Unused local variable…” using multiple JavaScript template files

I'm using PyCharm for my Django project and In my file product_header_js.html :

<script>
    {% include 'global_variables.js' %}
    {% include 'update_scene_function.js' %}
    ...
    // I may use variables in here or in update_scene_function.js
</script>

I would like to use variables in global_variables.js in my update_scene_function.js file and product_header_js.html file. PyCharm lets me do this, but gives me the error Unused local variable... in global_variables.js and all my variables are greyed out because PyCharm doesn't think they are being used. Is there anyway to fix PyCharm?

So what generated this question was me trying to modularize my JavaScript code, but it looks like I might have to just deal with the PyCharm warnings. Even when I add JavaScript as a template file type, PyCharm's JavaScript interpreter still gives me warnings (not Django template tag warnings) when I do something like this:

{% if something %}
    var my_var = "a";
{% else %}
    var my_var = "b";
{% endif %}

It'll say Duplicate declaration . And when I reference a variable not in the current template file or when I don't use a variable declared in the current template, PyCharm complains.

So in summary, you can do this, but PyCharm will complain and the CTRL + clicking to jump to declarations doesn't work.

One of my follow-up questions would be, if you can tolerate the PyCharm warnings, is including JavaScript files better performing than multiple external JavaScript files (). I would think including would perform better most of the time (except if most of your traffic is returning visitors where you could use external JavaScript files and leverage caching).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM