How can I fix the "Calling format_html() without passing args or kwargs is deprecated." in PyCharm?
I have the following code:
def _demo_preview_message(request):
if not getattr(settings, 'IS_DEMO', False):
return
last = DemoEmail.objects.order_by('-id').first()
if last:
messages.success(
request=request,
message=format_html("Email queued (demo). <a href='{}'>Preview</a>",
reverse('demo_outbox_detail', args=[last.pk]))
)
At the line:
message=format_html("Email queued (demo). <a href='{}'>Preview</a>",
reverse('demo_outbox_detail', args=[last.pk]))
PyCharm gives me the following message:
Calling format_html() without passing args or kwargs is deprecated.
How can I fix this?
Seems to be a code analysis issue from PyCharms side so no need to fix this if everything works fine when ran.
If this really bothers you, you could maybe disable it in pycharm: Preferences -> Editor -> Inspections
In PyCharm, you can disable inspections of individual lines by adding # noqa at the end of the subject line. This will suppress any warnings and error messages for that line only.
message=format_html("Email queued (demo). <a href='{}'>Preview</a>",
reverse('demo_outbox_detail', args=[last.pk])) # noqa
Alternatively, you can disable "classes" of inspections by adding a line at the top of the script:
# noqa F401, E501
# < the rest of your code >
which will silence all messages with those codes. I prefer only using the latter to suppress codes that I don't really care about anywhere in my code like E501 which flags lines that are too long. I generally use # noqa at the line level as my default and do it sparingly.
Edit: Just to clarify, you need to enter the code for the warning you're getting; the ones above are just examples.