I need to refactor existing Django code, by using {% static 'path/to/file' %}
tag. I think it's possible to use PyCharm feature "Replace in path" with regex option.
So, I need to replace my script tags, which now look like:
<script type="text/javascript" src="/static/js/script.js"></script>
To look like:
<script type="text/javascript" src="{% static 'js/script.js' %}"></script>
Here is PyCharm "Replace in Path" window:
I think I should pass in "Text to find" something like src="([^"]+)"
, but what should I pass in "Replace with", I can't understand.
Simplified version of your regex would be src="(.+?)"
. Instead, you can use the following expression to match
src="/static/(.+?)"
And replace with
src="{% static '$1' %}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With