In Django, there’s the existence of a message framework which notifies the user after an action is performed. For instance, from the views.py there might something like:
if success:
messages.success(request, 'Update Successful')
else:
messages.warning(request, 'Something is missing')
I believe Rails have something similar with:
flash[:notice] = 'Something is missing'
Should the messages above be hard-coded in the controller?
If I understand your question, you are asking whether or not you should hard-code a string value into your code. In compiled languages, you often use a reference to a string, instead of entering the actual string. ala:
This gives you the freedom to change the string value without re-compiling the code, and has a performance benefit in some instances.
Because Python is dynamic this really isn’t required, but depending on the size of the project, may be beneficial.
Imagine a situation where the software is used by people speaking different languages, you could detect the required language somewhere else in your code and initialize
message_resource.success, as well as any other strings, to be in said language.here is a simple example:
german.py
english.py
main.py