How to handle the case when positional arguments are not provided in the URL?

I am trying to add a feature to my site wherein users can add custom emojis.

So I have written an HTML form where the user enters an emoji name, along with an image, and then clicks on the submit button. Then I take that emoji name, send a POST request to the URL app/emoji/<emoji_name>, and update the database.
But when the user provides only the image, and not the emoji name, the request is sent to app/emoji/, which gives a 404 Not Found error. Is there any way to know if the user provided the name and warn if not?

I can do this using javascript, but is there any way to do this using Django? I have multiple such cases where I need to check if the user provided some data or not.

Well, since you don’t want to use JavaScript, you have no choice but to wait for them to click submit. You can’t warn them about anything because Django doesn’t see the form until it’s submitted.

If you want to handle it on the server side, then you could handle it by handling the ‘app/emoji/’ url as the error condition.

However, I’d really recommend taking the emoji_name out of the url and just passing it as post data in the form along with the image and any other data that needs to be sent along. You can then validate that field in the same way you validate all other form fields.

Thanks for the reply.

If you want to handle it on the server side, then you could handle it by handling the ‘app/emoji/’ url as the error condition.

I handle everything on the server side, but this particular case is troubling me.

However, I’d really recommend taking the emoji_name out of the URL

I can’t because I also use it to delete an emoji.

I’m not sure I understand what the trouble is. You assign that URL to a view that identifies that the submission is invalid.

I don’t understand why that would make a difference.