I am writing a tag system. The user enters several tags:
abc, def, ghi,
But if they use a trailing comma, the code considers that there are 4 tags, not three.
In my code I write:
if "tags" in request.POST:
tags = request.POST["tags"]
tag_list = [Tag.objects.get_or_create(name = tag.lstrip())[0] for tag in tags.split(",")]
In this case, a tag is created. '' How can I change the code to ignore any entry that I suppose len (str) = 0?
source
share