django-urls-8

Last Updated :
Discuss
Comments

In a view, how to make a random 6-char slug with letters and numbers?

Use hash(original_url)[:6].

datetime.now() string.

len(original_url) for length.

''.join(random.choices('abc123def456', k=6)).

Tags:
Share your thoughts in the comments